Skip to content

Commit 91c4db0

Browse files
committed
[clang-format][NFC] Replace !is() with isNot()
Differential Revision: https://reviews.llvm.org/D158571
1 parent 185bf56 commit 91c4db0

13 files changed

+115
-109
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,11 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
430430
return true;
431431
}
432432

433-
if (Current.is(TT_ObjCMethodExpr) && !Previous.is(TT_SelectorName) &&
433+
if (Current.is(TT_ObjCMethodExpr) && Previous.isNot(TT_SelectorName) &&
434434
State.Line->startsWith(TT_ObjCMethodSpecifier)) {
435435
return true;
436436
}
437-
if (Current.is(TT_SelectorName) && !Previous.is(tok::at) &&
437+
if (Current.is(TT_SelectorName) && Previous.isNot(tok::at) &&
438438
CurrentState.ObjCSelectorNameFound && CurrentState.BreakBeforeParameter &&
439439
(Style.ObjCBreakBeforeNestedBlockParam ||
440440
!Current.startsSequence(TT_SelectorName, tok::colon, tok::caret))) {
@@ -469,7 +469,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
469469
return true;
470470
}
471471

472-
if (!State.Line->First->is(tok::kw_enum) && State.Column <= NewLineColumn)
472+
if (State.Line->First->isNot(tok::kw_enum) && State.Column <= NewLineColumn)
473473
return false;
474474

475475
if (Style.AlwaysBreakBeforeMultilineStrings &&
@@ -578,8 +578,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
578578
// Don't always break between a JavaScript `function` and the function
579579
// name.
580580
!Style.isJavaScript()) ||
581-
(Current.is(tok::kw_operator) && !Previous.is(tok::coloncolon))) &&
582-
!Previous.is(tok::kw_template) && CurrentState.BreakBeforeParameter) {
581+
(Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
582+
Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
583583
return true;
584584
}
585585

@@ -815,7 +815,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
815815
// Exclude relational operators, as there, it is always more desirable to
816816
// have the LHS 'left' of the RHS.
817817
const FormatToken *P = Current.getPreviousNonComment();
818-
if (!Current.is(tok::comment) && P &&
818+
if (Current.isNot(tok::comment) && P &&
819819
(P->isOneOf(TT_BinaryOperator, tok::comma) ||
820820
(P->is(TT_ConditionalExpr) && P->is(tok::colon))) &&
821821
!P->isOneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
@@ -830,8 +830,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
830830
// Don't do this if there are only two operands. In these cases, there is
831831
// always a nice vertical separation between them and the extra line break
832832
// does not help.
833-
bool HasTwoOperands =
834-
P->OperatorIndex == 0 && !P->NextOperator && !P->is(TT_ConditionalExpr);
833+
bool HasTwoOperands = P->OperatorIndex == 0 && !P->NextOperator &&
834+
P->isNot(TT_ConditionalExpr);
835835
if ((!BreakBeforeOperator &&
836836
!(HasTwoOperands &&
837837
Style.AlignOperands != FormatStyle::OAS_DontAlign)) ||
@@ -850,7 +850,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
850850
CurrentState.NestedBlockIndent = State.Column;
851851
} else if (!Current.isOneOf(tok::comment, tok::caret) &&
852852
((Previous.is(tok::comma) &&
853-
!Previous.is(TT_OverloadedOperator)) ||
853+
Previous.isNot(TT_OverloadedOperator)) ||
854854
(Previous.is(tok::colon) && Previous.is(TT_ObjCMethodExpr)))) {
855855
CurrentState.LastSpace = State.Column;
856856
} else if (Previous.is(TT_CtorInitializerColon) &&
@@ -952,9 +952,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
952952
//
953953
// is common and should be formatted like a free-standing function. The same
954954
// goes for wrapping before the lambda return type arrow.
955-
if (!Current.is(TT_LambdaArrow) &&
955+
if (Current.isNot(TT_LambdaArrow) &&
956956
(!Style.isJavaScript() || Current.NestingLevel != 0 ||
957-
!PreviousNonComment || !PreviousNonComment->is(tok::equal) ||
957+
!PreviousNonComment || PreviousNonComment->isNot(tok::equal) ||
958958
!Current.isOneOf(Keywords.kw_async, Keywords.kw_function))) {
959959
CurrentState.NestedBlockIndent = State.Column;
960960
}
@@ -1418,7 +1418,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
14181418
if (Current.is(TT_BinaryOperator) && Current.isNot(tok::lessless))
14191419
CurrentState.LastOperatorWrapped = Newline;
14201420
if (Current.is(TT_ConditionalExpr) && Current.Previous &&
1421-
!Current.Previous->is(TT_ConditionalExpr)) {
1421+
Current.Previous->isNot(TT_ConditionalExpr)) {
14221422
CurrentState.LastOperatorWrapped = Newline;
14231423
}
14241424
if (Current.is(TT_ArraySubscriptLSquare) &&
@@ -1447,7 +1447,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
14471447
CurrentState.QuestionColumn = State.Column;
14481448
}
14491449
if (!Current.opensScope() && !Current.closesScope() &&
1450-
!Current.is(TT_PointerOrReference)) {
1450+
Current.isNot(TT_PointerOrReference)) {
14511451
State.LowestLevelOnLine =
14521452
std::min(State.LowestLevelOnLine, Current.NestingLevel);
14531453
}
@@ -1511,7 +1511,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
15111511
// }, a, b, c);
15121512
if (Current.isNot(tok::comment) && !Current.ClosesRequiresClause &&
15131513
Previous && Previous->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
1514-
!Previous->is(TT_DictLiteral) && State.Stack.size() > 1 &&
1514+
Previous->isNot(TT_DictLiteral) && State.Stack.size() > 1 &&
15151515
!CurrentState.HasMultipleNestedBlocks) {
15161516
if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)
15171517
for (ParenState &PState : llvm::drop_end(State.Stack))
@@ -1641,7 +1641,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
16411641
// ParameterToInnerFunction));
16421642
if (PrecedenceLevel > prec::Unknown)
16431643
NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
1644-
if (PrecedenceLevel != prec::Conditional && !Current.is(TT_UnaryOperator) &&
1644+
if (PrecedenceLevel != prec::Conditional &&
1645+
Current.isNot(TT_UnaryOperator) &&
16451646
Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) {
16461647
NewParenState.StartOfFunctionCall = State.Column;
16471648
}
@@ -2146,7 +2147,7 @@ unsigned ContinuationIndenter::handleEndOfLine(const FormatToken &Current,
21462147
static StringRef getEnclosingFunctionName(const FormatToken &Current) {
21472148
// Look for: 'function(' or 'function<templates>(' before Current.
21482149
auto Tok = Current.getPreviousNonComment();
2149-
if (!Tok || !Tok->is(tok::l_paren))
2150+
if (!Tok || Tok->isNot(tok::l_paren))
21502151
return "";
21512152
Tok = Tok->getPreviousNonComment();
21522153
if (!Tok)
@@ -2156,7 +2157,7 @@ static StringRef getEnclosingFunctionName(const FormatToken &Current) {
21562157
if (Tok)
21572158
Tok = Tok->getPreviousNonComment();
21582159
}
2159-
if (!Tok || !Tok->is(tok::identifier))
2160+
if (!Tok || Tok->isNot(tok::identifier))
21602161
return "";
21612162
return Tok->TokenText;
21622163
}

clang/lib/Format/DefinitionBlockSeparator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ void DefinitionBlockSeparator::separateBlocks(
187187
InsertReplacement(OpeningLineIndex != 0);
188188
TargetLine = CurrentLine;
189189
TargetToken = TargetLine->First;
190-
while (TargetToken && !TargetToken->is(tok::r_brace))
190+
while (TargetToken && TargetToken->isNot(tok::r_brace))
191191
TargetToken = TargetToken->Next;
192192
if (!TargetToken)
193-
while (I < Lines.size() && !Lines[I]->First->is(tok::r_brace))
193+
while (I < Lines.size() && Lines[I]->First->isNot(tok::r_brace))
194194
++I;
195195
} else if (CurrentLine->First->closesScope()) {
196196
if (OpeningLineIndex > Lines.size())

clang/lib/Format/Format.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ class Formatter : public TokenAnalyzer {
24172417
for (const AnnotatedLine *Line : Lines) {
24182418
AlignmentDiff += countVariableAlignments(Line->Children);
24192419
for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
2420-
if (!Tok->is(TT_PointerOrReference))
2420+
if (Tok->isNot(TT_PointerOrReference))
24212421
continue;
24222422
// Don't treat space in `void foo() &&` as evidence.
24232423
if (const auto *Prev = Tok->getPreviousNonComment()) {
@@ -2688,7 +2688,7 @@ class Cleaner : public TokenAnalyzer {
26882688
bool DeleteLeft) {
26892689
auto NextNotDeleted = [this](const FormatToken &Tok) -> FormatToken * {
26902690
for (auto *Res = Tok.Next; Res; Res = Res->Next) {
2691-
if (!Res->is(tok::comment) &&
2691+
if (Res->isNot(tok::comment) &&
26922692
DeletedTokens.find(Res) == DeletedTokens.end()) {
26932693
return Res;
26942694
}

clang/lib/Format/FormatToken.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ struct FormatToken {
727727
/// Returns \c true if this is a string literal that's like a label,
728728
/// e.g. ends with "=" or ":".
729729
bool isLabelString() const {
730-
if (!is(tok::string_literal))
730+
if (isNot(tok::string_literal))
731731
return false;
732732
StringRef Content = TokenText;
733733
if (Content.startswith("\"") || Content.startswith("'"))

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ bool FormatTokenLexer::tryMergeNSStringLiteral() {
277277
return false;
278278
auto &At = *(Tokens.end() - 2);
279279
auto &String = *(Tokens.end() - 1);
280-
if (!At->is(tok::at) || !String->is(tok::string_literal))
280+
if (At->isNot(tok::at) || String->isNot(tok::string_literal))
281281
return false;
282282
At->Tok.setKind(tok::string_literal);
283283
At->TokenText = StringRef(At->TokenText.begin(),
@@ -295,7 +295,7 @@ bool FormatTokenLexer::tryMergeJSPrivateIdentifier() {
295295
return false;
296296
auto &Hash = *(Tokens.end() - 2);
297297
auto &Identifier = *(Tokens.end() - 1);
298-
if (!Hash->is(tok::hash) || !Identifier->is(tok::identifier))
298+
if (Hash->isNot(tok::hash) || Identifier->isNot(tok::identifier))
299299
return false;
300300
Hash->Tok.setKind(tok::identifier);
301301
Hash->TokenText =
@@ -360,7 +360,7 @@ bool FormatTokenLexer::tryMergeNullishCoalescingEqual() {
360360
auto &NullishCoalescing = *(Tokens.end() - 2);
361361
auto &Equal = *(Tokens.end() - 1);
362362
if (NullishCoalescing->getType() != TT_NullCoalescingOperator ||
363-
!Equal->is(tok::equal)) {
363+
Equal->isNot(tok::equal)) {
364364
return false;
365365
}
366366
NullishCoalescing->Tok.setKind(tok::equal); // no '??=' in clang tokens.
@@ -399,7 +399,7 @@ bool FormatTokenLexer::tryTransformCSharpForEach() {
399399
if (Tokens.size() < 1)
400400
return false;
401401
auto &Identifier = *(Tokens.end() - 1);
402-
if (!Identifier->is(tok::identifier))
402+
if (Identifier->isNot(tok::identifier))
403403
return false;
404404
if (Identifier->TokenText != "foreach")
405405
return false;
@@ -414,9 +414,9 @@ bool FormatTokenLexer::tryMergeForEach() {
414414
return false;
415415
auto &For = *(Tokens.end() - 2);
416416
auto &Each = *(Tokens.end() - 1);
417-
if (!For->is(tok::kw_for))
417+
if (For->isNot(tok::kw_for))
418418
return false;
419-
if (!Each->is(tok::identifier))
419+
if (Each->isNot(tok::identifier))
420420
return false;
421421
if (Each->TokenText != "each")
422422
return false;
@@ -435,7 +435,7 @@ bool FormatTokenLexer::tryTransformTryUsageForC() {
435435
if (Tokens.size() < 2)
436436
return false;
437437
auto &Try = *(Tokens.end() - 2);
438-
if (!Try->is(tok::kw_try))
438+
if (Try->isNot(tok::kw_try))
439439
return false;
440440
auto &Next = *(Tokens.end() - 1);
441441
if (Next->isOneOf(tok::l_brace, tok::colon, tok::hash, tok::comment))
@@ -511,7 +511,7 @@ bool FormatTokenLexer::tryMergeTokens(ArrayRef<tok::TokenKind> Kinds,
511511
SmallVectorImpl<FormatToken *>::const_iterator First =
512512
Tokens.end() - Kinds.size();
513513
for (unsigned i = 0; i < Kinds.size(); ++i)
514-
if (!First[i]->is(Kinds[i]))
514+
if (First[i]->isNot(Kinds[i]))
515515
return false;
516516

517517
return tryMergeTokens(Kinds.size(), NewType);
@@ -852,14 +852,14 @@ bool FormatTokenLexer::tryMerge_TMacro() {
852852
if (Tokens.size() < 4)
853853
return false;
854854
FormatToken *Last = Tokens.back();
855-
if (!Last->is(tok::r_paren))
855+
if (Last->isNot(tok::r_paren))
856856
return false;
857857

858858
FormatToken *String = Tokens[Tokens.size() - 2];
859-
if (!String->is(tok::string_literal) || String->IsMultiline)
859+
if (String->isNot(tok::string_literal) || String->IsMultiline)
860860
return false;
861861

862-
if (!Tokens[Tokens.size() - 3]->is(tok::l_paren))
862+
if (Tokens[Tokens.size() - 3]->isNot(tok::l_paren))
863863
return false;
864864

865865
FormatToken *Macro = Tokens[Tokens.size() - 4];

clang/lib/Format/FormatTokenSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class IndexedTokenSource : public FormatTokenSource {
9999
}
100100

101101
FormatToken *getPreviousToken() override {
102-
assert(Position <= 0 || !Tokens[Position - 1]->is(tok::eof));
102+
assert(Position <= 0 || Tokens[Position - 1]->isNot(tok::eof));
103103
return Position > 0 ? Tokens[Position - 1] : nullptr;
104104
}
105105

clang/lib/Format/MacroExpander.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MacroExpander::DefinitionParser {
5555
// Parse the token stream and return the corresponding Definition object.
5656
// Returns an empty definition object with a null-Name on error.
5757
MacroExpander::Definition parse() {
58-
if (!Current->is(tok::identifier))
58+
if (Current->isNot(tok::identifier))
5959
return {};
6060
Def.Name = Current->TokenText;
6161
nextToken();
@@ -191,7 +191,7 @@ MacroExpander::expand(FormatToken *ID,
191191
auto expandArgument = [&](FormatToken *Tok) -> bool {
192192
// If the current token references a parameter, expand the corresponding
193193
// argument.
194-
if (!Tok->is(tok::identifier) || ExpandedArgs.contains(Tok->TokenText))
194+
if (Tok->isNot(tok::identifier) || ExpandedArgs.contains(Tok->TokenText))
195195
return false;
196196
ExpandedArgs.insert(Tok->TokenText);
197197
auto I = Def.ArgMap.find(Tok->TokenText);

clang/lib/Format/QualifierAlignmentFixer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
181181
tooling::Replacements &Fixes, const FormatToken *const Tok,
182182
const std::string &Qualifier, tok::TokenKind QualifierType) {
183183
// We only need to think about streams that begin with a qualifier.
184-
if (!Tok->is(QualifierType))
184+
if (Tok->isNot(QualifierType))
185185
return Tok;
186186
// Don't concern yourself if nothing follows the qualifier.
187187
if (!Tok->Next)
@@ -367,7 +367,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
367367
tooling::Replacements &Fixes, const FormatToken *const Tok,
368368
const std::string &Qualifier, tok::TokenKind QualifierType) {
369369
// We only need to think about streams that begin with a qualifier.
370-
if (!Tok->is(QualifierType))
370+
if (Tok->isNot(QualifierType))
371371
return Tok;
372372
// Don't concern yourself if nothing preceeds the qualifier.
373373
if (!Tok->getPreviousNonComment())
@@ -614,7 +614,7 @@ bool LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
614614
bool LeftRightQualifierAlignmentFixer::isPossibleMacro(const FormatToken *Tok) {
615615
if (!Tok)
616616
return false;
617-
if (!Tok->is(tok::identifier))
617+
if (Tok->isNot(tok::identifier))
618618
return false;
619619
if (Tok->TokenText.upper() == Tok->TokenText.str()) {
620620
// T,K,U,V likely could be template arguments

clang/lib/Format/SortJavaScriptImports.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
530530
nextToken();
531531
if (Current->is(tok::semi))
532532
return true;
533-
if (!Current->is(tok::period))
533+
if (Current->isNot(tok::period))
534534
return false;
535535
nextToken();
536536
}

0 commit comments

Comments
 (0)