Skip to content

Commit 847e1e1

Browse files
[clang-format][NFC] Introduce isNoneOf (#161021)
And apply throughout the code base.
1 parent 5be4fc2 commit 847e1e1

14 files changed

+119
-116
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
368368

369369
// If binary operators are moved to the next line (including commas for some
370370
// styles of constructor initializers), that's always ok.
371-
if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&
371+
if (Current.isNoneOf(TT_BinaryOperator, tok::comma) &&
372372
// Allow breaking opening brace of lambdas (when passed as function
373373
// arguments) to a new line when BeforeLambdaBody brace wrapping is
374374
// enabled.
@@ -445,7 +445,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
445445
(!Style.BreakBeforeTernaryOperators &&
446446
Previous.is(TT_ConditionalExpr))) &&
447447
CurrentState.BreakBeforeParameter && !Current.isTrailingComment() &&
448-
!Current.isOneOf(tok::r_paren, tok::r_brace)) {
448+
Current.isNoneOf(tok::r_paren, tok::r_brace)) {
449449
return true;
450450
}
451451
if (CurrentState.IsChainedConditional &&
@@ -523,9 +523,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
523523
if (Style.AlwaysBreakBeforeMultilineStrings &&
524524
(NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
525525
Previous.is(tok::comma) || Current.NestingLevel < 2) &&
526-
!Previous.isOneOf(tok::kw_return, tok::lessless, tok::at,
526+
Previous.isNoneOf(tok::kw_return, tok::lessless, tok::at,
527527
Keywords.kw_dollar) &&
528-
!Previous.isOneOf(TT_InlineASMColon, TT_ConditionalExpr) &&
528+
Previous.isNoneOf(TT_InlineASMColon, TT_ConditionalExpr) &&
529529
nextIsMultilineString(State)) {
530530
return true;
531531
}
@@ -648,7 +648,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
648648
// into the ColumnLimit, they are checked here in the ContinuationIndenter.
649649
if (Style.ColumnLimit != 0 && Previous.is(BK_Block) &&
650650
Previous.is(tok::l_brace) &&
651-
!Current.isOneOf(tok::r_brace, tok::comment)) {
651+
Current.isNoneOf(tok::r_brace, tok::comment)) {
652652
return true;
653653
}
654654

@@ -752,7 +752,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
752752
return false;
753753

754754
const auto *Next = Comma->getNextNonComment();
755-
return Next && !Next->isOneOf(TT_LambdaLSquare, tok::l_brace, tok::caret);
755+
return Next && Next->isNoneOf(TT_LambdaLSquare, tok::l_brace, tok::caret);
756756
};
757757

758758
if (DisallowLineBreaks())
@@ -835,15 +835,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
835835
return Tok.is(tok::l_brace) && Tok.isNot(BK_Block) &&
836836
Style.Cpp11BracedListStyle;
837837
};
838-
if (!Tok.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
838+
if (Tok.isNoneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
839839
!IsStartOfBracedList()) {
840840
return false;
841841
}
842842
if (!Tok.Previous)
843843
return true;
844844
if (Tok.Previous->isIf())
845845
return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
846-
return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
846+
return Tok.Previous->isNoneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
847847
tok::kw_switch) &&
848848
!(Style.isJavaScript() && Tok.Previous->is(Keywords.kw_await));
849849
};
@@ -882,8 +882,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
882882
Tok.isOneOf(tok::ellipsis, Keywords.kw_await))) {
883883
return true;
884884
}
885-
const auto *Previous = Tok.Previous;
886-
if (!Previous || (!Previous->isOneOf(TT_FunctionDeclarationLParen,
885+
if (const auto *Previous = Tok.Previous;
886+
!Previous || (Previous->isNoneOf(TT_FunctionDeclarationLParen,
887887
TT_LambdaDefinitionLParen) &&
888888
!IsFunctionCallParen(*Previous))) {
889889
return true;
@@ -920,9 +920,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
920920
// align the commas with the opening paren.
921921
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
922922
!CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
923-
Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
924-
Previous.isNot(TT_TableGenDAGArgOpener) &&
925-
Previous.isNot(TT_TableGenDAGArgOpenerToBreak) &&
923+
Previous.isNoneOf(TT_ObjCMethodExpr, TT_RequiresClause,
924+
TT_TableGenDAGArgOpener,
925+
TT_TableGenDAGArgOpenerToBreak) &&
926926
!(Current.MacroParent && Previous.MacroParent) &&
927927
(Current.isNot(TT_LineComment) ||
928928
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen)) &&
@@ -962,7 +962,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
962962
if (Current.isNot(tok::comment) && P &&
963963
(P->isOneOf(TT_BinaryOperator, tok::comma) ||
964964
(P->is(TT_ConditionalExpr) && P->is(tok::colon))) &&
965-
!P->isOneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
965+
P->isNoneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
966966
P->getPrecedence() != prec::Assignment &&
967967
P->getPrecedence() != prec::Relational &&
968968
P->getPrecedence() != prec::Spaceship) {
@@ -992,7 +992,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
992992
// parameter, i.e. let nested calls have a continuation indent.
993993
CurrentState.LastSpace = State.Column;
994994
CurrentState.NestedBlockIndent = State.Column;
995-
} else if (!Current.isOneOf(tok::comment, tok::caret) &&
995+
} else if (Current.isNoneOf(tok::comment, tok::caret) &&
996996
((Previous.is(tok::comma) &&
997997
Previous.isNot(TT_OverloadedOperator)) ||
998998
(Previous.is(tok::colon) && Previous.is(TT_ObjCMethodExpr)))) {
@@ -1099,7 +1099,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
10991099
if (Current.isNot(TT_LambdaArrow) &&
11001100
(!Style.isJavaScript() || Current.NestingLevel != 0 ||
11011101
!PreviousNonComment || PreviousNonComment->isNot(tok::equal) ||
1102-
!Current.isOneOf(Keywords.kw_async, Keywords.kw_function))) {
1102+
Current.isNoneOf(Keywords.kw_async, Keywords.kw_function))) {
11031103
CurrentState.NestedBlockIndent = State.Column;
11041104
}
11051105

@@ -1239,11 +1239,11 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
12391239
}
12401240

12411241
if (PreviousNonComment &&
1242-
!PreviousNonComment->isOneOf(tok::comma, tok::colon, tok::semi) &&
1242+
PreviousNonComment->isNoneOf(tok::comma, tok::colon, tok::semi) &&
12431243
((PreviousNonComment->isNot(TT_TemplateCloser) &&
12441244
!PreviousNonComment->ClosesRequiresClause) ||
12451245
Current.NestingLevel != 0) &&
1246-
!PreviousNonComment->isOneOf(
1246+
PreviousNonComment->isNoneOf(
12471247
TT_BinaryOperator, TT_FunctionAnnotationRParen, TT_JavaAnnotation,
12481248
TT_LeadingJavaAnnotation) &&
12491249
Current.isNot(TT_BinaryOperator) && !PreviousNonComment->opensScope() &&
@@ -1281,8 +1281,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
12811281
bool AllowAllConstructorInitializersOnNextLine =
12821282
Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine ||
12831283
Style.PackConstructorInitializers == FormatStyle::PCIS_NextLineOnly;
1284-
if (!(Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) ||
1285-
PreviousIsBreakingCtorInitializerColon) ||
1284+
if ((Previous.isNoneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) &&
1285+
!PreviousIsBreakingCtorInitializerColon) ||
12861286
(!Style.AllowAllParametersOfDeclarationOnNextLine &&
12871287
State.Line->MustBeDeclaration) ||
12881288
(!Style.AllowAllArgumentsOnNextLine &&
@@ -1576,7 +1576,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
15761576
if (Previous.is(tok::r_paren) &&
15771577
Previous.isNot(TT_TableGenDAGArgOperatorToBreak) &&
15781578
!Current.isBinaryOperator() &&
1579-
!Current.isOneOf(tok::colon, tok::comment)) {
1579+
Current.isNoneOf(tok::colon, tok::comment)) {
15801580
return ContinuationIndent;
15811581
}
15821582
if (Current.is(TT_ProtoExtensionLSquare))
@@ -1591,7 +1591,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
15911591
NextNonComment->SpacesRequiredBefore;
15921592
}
15931593
if (CurrentState.Indent == State.FirstIndent && PreviousNonComment &&
1594-
!PreviousNonComment->isOneOf(tok::r_brace, TT_CtorInitializerComma)) {
1594+
PreviousNonComment->isNoneOf(tok::r_brace, TT_CtorInitializerComma)) {
15951595
// Ensure that we fall back to the continuation indent width instead of
15961596
// just flushing continuations left.
15971597
return CurrentState.Indent + Style.ContinuationIndentWidth;
@@ -1734,7 +1734,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
17341734
}
17351735
if (Previous && (Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) ||
17361736
(Previous->isOneOf(tok::l_paren, tok::comma, tok::colon) &&
1737-
!Previous->isOneOf(TT_DictLiteral, TT_ObjCMethodExpr,
1737+
Previous->isNoneOf(TT_DictLiteral, TT_ObjCMethodExpr,
17381738
TT_CtorInitializerColon)))) {
17391739
CurrentState.NestedBlockInlined =
17401740
!Newline && hasNestedBlockInlined(Previous, Current, Style);
@@ -1758,7 +1758,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
17581758
State.StartOfStringLiteral = State.Column + 1;
17591759
} else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
17601760
State.StartOfStringLiteral = State.Column;
1761-
} else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
1761+
} else if (Current.isNoneOf(tok::comment, tok::identifier, tok::hash) &&
17621762
!Current.isStringLiteral()) {
17631763
State.StartOfStringLiteral = 0;
17641764
}
@@ -2057,7 +2057,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
20572057
// array literals as these follow different indentation rules.
20582058
bool NoLineBreak =
20592059
Current.Children.empty() &&
2060-
!Current.isOneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&
2060+
Current.isNoneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&
20612061
(CurrentState.NoLineBreak || CurrentState.NoLineBreakInOperand ||
20622062
(Current.is(TT_TemplateOpener) &&
20632063
CurrentState.ContainsUnwrappedBuilder));

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2435,7 +2435,7 @@ class BracesRemover : public TokenAnalyzer {
24352435
const auto *NextLine = I + 1 == End ? nullptr : I[1];
24362436
for (const auto *Token = Line->First; Token && !Token->Finalized;
24372437
Token = Token->Next) {
2438-
if (!Token->Optional || !Token->isOneOf(tok::l_brace, tok::r_brace))
2438+
if (!Token->Optional || Token->isNoneOf(tok::l_brace, tok::r_brace))
24392439
continue;
24402440
auto *Next = Token->Next;
24412441
assert(Next || Token == Line->Last);

clang/lib/Format/FormatToken.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
108108
// Ensure that we start on the opening brace.
109109
const FormatToken *LBrace =
110110
State.NextToken->Previous->getPreviousNonComment();
111-
if (!LBrace || !LBrace->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
111+
if (!LBrace || LBrace->isNoneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
112112
LBrace->is(BK_Block) || LBrace->is(TT_DictLiteral) ||
113113
LBrace->Next->is(TT_DesignatedInitializerPeriod)) {
114114
return 0;
@@ -177,7 +177,7 @@ static unsigned CodePointsBetween(const FormatToken *Begin,
177177
void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
178178
// FIXME: At some point we might want to do this for other lists, too.
179179
if (!Token->MatchingParen ||
180-
!Token->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
180+
Token->isNoneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
181181
return;
182182
}
183183

clang/lib/Format/FormatToken.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ struct FormatToken {
645645
return is(K1) || isOneOf(K2, Ks...);
646646
}
647647
template <typename T> bool isNot(T Kind) const { return !is(Kind); }
648+
template <typename... Ts> bool isNoneOf(Ts... Ks) const {
649+
return !isOneOf(Ks...);
650+
}
648651

649652
bool isIf(bool AllowConstexprMacro = true) const {
650653
return is(tok::kw_if) || endsSequence(tok::kw_constexpr, tok::kw_if) ||
@@ -748,7 +751,7 @@ struct FormatToken {
748751
/// Returns \c true if this is a "." or "->" accessing a member.
749752
bool isMemberAccess() const {
750753
return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
751-
!isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
754+
isNoneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
752755
TT_LambdaArrow, TT_LeadingJavaAnnotation);
753756
}
754757

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ void FormatTokenLexer::tryParseJavaTextBlock() {
733733
// its text if successful.
734734
void FormatTokenLexer::tryParseJSRegexLiteral() {
735735
FormatToken *RegexToken = Tokens.back();
736-
if (!RegexToken->isOneOf(tok::slash, tok::slashequal))
736+
if (RegexToken->isNoneOf(tok::slash, tok::slashequal))
737737
return;
738738

739739
FormatToken *Prev = nullptr;
@@ -1041,7 +1041,7 @@ void FormatTokenLexer::handleTemplateStrings() {
10411041

10421042
void FormatTokenLexer::tryParsePythonComment() {
10431043
FormatToken *HashToken = Tokens.back();
1044-
if (!HashToken->isOneOf(tok::hash, tok::hashhash))
1044+
if (HashToken->isNoneOf(tok::hash, tok::hashhash))
10451045
return;
10461046
// Turn the remainder of this line into a comment.
10471047
const char *CommentBegin =

clang/lib/Format/MacroExpander.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class MacroExpander::DefinitionParser {
8686
}
8787

8888
bool parseExpansion() {
89-
if (!Current->isOneOf(tok::equal, tok::eof))
89+
if (Current->isNoneOf(tok::equal, tok::eof))
9090
return false;
9191
if (Current->is(tok::equal))
9292
nextToken();

clang/lib/Format/NamespaceEndCommentsFixer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::string computeName(const FormatToken *NamespaceTok) {
7070
// and closing parenthesis or comma.
7171
assert(Tok && Tok->is(tok::l_paren) && "expected an opening parenthesis");
7272
Tok = Tok->getNextNonComment();
73-
while (Tok && !Tok->isOneOf(tok::r_paren, tok::comma)) {
73+
while (Tok && Tok->isNoneOf(tok::r_paren, tok::comma)) {
7474
name += Tok->TokenText;
7575
Tok = Tok->getNextNonComment();
7676
}
@@ -85,7 +85,7 @@ std::string computeName(const FormatToken *NamespaceTok) {
8585
// one token before that up until the '{'. A '(' might be a macro with
8686
// arguments.
8787
const FormatToken *FirstNSTok = nullptr;
88-
while (Tok && !Tok->isOneOf(tok::l_brace, tok::coloncolon, tok::l_paren)) {
88+
while (Tok && Tok->isNoneOf(tok::l_brace, tok::coloncolon, tok::l_paren)) {
8989
if (FirstNSTok)
9090
FirstNSName += FirstNSTok->TokenText;
9191
FirstNSTok = Tok;

clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
6161
}
6262

6363
// Most attributes look like identifiers, but `class` is a keyword.
64-
if (!Tok->isOneOf(tok::identifier, tok::kw_class)) {
64+
if (Tok->isNoneOf(tok::identifier, tok::kw_class)) {
6565
// If we hit any other kind of token, just bail.
6666
return;
6767
}

clang/lib/Format/QualifierAlignmentFixer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
508508

509509
// Don't change declarations such as
510510
// `foo(struct Foo const a);` -> `foo(struct Foo const a);`
511-
if (!Previous || !Previous->isOneOf(tok::kw_struct, tok::kw_class)) {
511+
if (!Previous || Previous->isNoneOf(tok::kw_struct, tok::kw_class)) {
512512
insertQualifierBefore(SourceMgr, Fixes, TypeToken, Qualifier);
513513
removeToken(SourceMgr, Fixes, Tok);
514514
}

clang/lib/Format/SortJavaScriptImports.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
439439
// for grammar EBNF (production ModuleItem).
440440
bool parseModuleReference(const AdditionalKeywords &Keywords,
441441
JsModuleReference &Reference) {
442-
if (!Current || !Current->isOneOf(Keywords.kw_import, tok::kw_export))
442+
if (!Current || Current->isNoneOf(Keywords.kw_import, tok::kw_export))
443443
return false;
444444
Reference.IsExport = Current->is(tok::kw_export);
445445

@@ -570,7 +570,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
570570
Symbol.Range.setEnd(Current->Tok.getLocation());
571571
Reference.Symbols.push_back(Symbol);
572572

573-
if (!Current->isOneOf(tok::r_brace, tok::comma))
573+
if (Current->isNoneOf(tok::r_brace, tok::comma))
574574
return false;
575575
}
576576
Reference.SymbolsEnd = Current->Tok.getLocation();

0 commit comments

Comments
 (0)