Skip to content

Commit

Permalink
[clang-format][NFC] Replace !is() with isNot()
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D158571
  • Loading branch information
owenca committed Aug 24, 2023
1 parent 185bf56 commit 91c4db0
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 109 deletions.
35 changes: 18 additions & 17 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,11 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;
}

if (Current.is(TT_ObjCMethodExpr) && !Previous.is(TT_SelectorName) &&
if (Current.is(TT_ObjCMethodExpr) && Previous.isNot(TT_SelectorName) &&
State.Line->startsWith(TT_ObjCMethodSpecifier)) {
return true;
}
if (Current.is(TT_SelectorName) && !Previous.is(tok::at) &&
if (Current.is(TT_SelectorName) && Previous.isNot(tok::at) &&
CurrentState.ObjCSelectorNameFound && CurrentState.BreakBeforeParameter &&
(Style.ObjCBreakBeforeNestedBlockParam ||
!Current.startsSequence(TT_SelectorName, tok::colon, tok::caret))) {
Expand Down Expand Up @@ -469,7 +469,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;
}

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

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

Expand Down Expand Up @@ -815,7 +815,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
// Exclude relational operators, as there, it is always more desirable to
// have the LHS 'left' of the RHS.
const FormatToken *P = Current.getPreviousNonComment();
if (!Current.is(tok::comment) && P &&
if (Current.isNot(tok::comment) && P &&
(P->isOneOf(TT_BinaryOperator, tok::comma) ||
(P->is(TT_ConditionalExpr) && P->is(tok::colon))) &&
!P->isOneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
Expand All @@ -830,8 +830,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
// Don't do this if there are only two operands. In these cases, there is
// always a nice vertical separation between them and the extra line break
// does not help.
bool HasTwoOperands =
P->OperatorIndex == 0 && !P->NextOperator && !P->is(TT_ConditionalExpr);
bool HasTwoOperands = P->OperatorIndex == 0 && !P->NextOperator &&
P->isNot(TT_ConditionalExpr);
if ((!BreakBeforeOperator &&
!(HasTwoOperands &&
Style.AlignOperands != FormatStyle::OAS_DontAlign)) ||
Expand All @@ -850,7 +850,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
CurrentState.NestedBlockIndent = State.Column;
} else if (!Current.isOneOf(tok::comment, tok::caret) &&
((Previous.is(tok::comma) &&
!Previous.is(TT_OverloadedOperator)) ||
Previous.isNot(TT_OverloadedOperator)) ||
(Previous.is(tok::colon) && Previous.is(TT_ObjCMethodExpr)))) {
CurrentState.LastSpace = State.Column;
} else if (Previous.is(TT_CtorInitializerColon) &&
Expand Down Expand Up @@ -952,9 +952,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
//
// is common and should be formatted like a free-standing function. The same
// goes for wrapping before the lambda return type arrow.
if (!Current.is(TT_LambdaArrow) &&
if (Current.isNot(TT_LambdaArrow) &&
(!Style.isJavaScript() || Current.NestingLevel != 0 ||
!PreviousNonComment || !PreviousNonComment->is(tok::equal) ||
!PreviousNonComment || PreviousNonComment->isNot(tok::equal) ||
!Current.isOneOf(Keywords.kw_async, Keywords.kw_function))) {
CurrentState.NestedBlockIndent = State.Column;
}
Expand Down Expand Up @@ -1418,7 +1418,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
if (Current.is(TT_BinaryOperator) && Current.isNot(tok::lessless))
CurrentState.LastOperatorWrapped = Newline;
if (Current.is(TT_ConditionalExpr) && Current.Previous &&
!Current.Previous->is(TT_ConditionalExpr)) {
Current.Previous->isNot(TT_ConditionalExpr)) {
CurrentState.LastOperatorWrapped = Newline;
}
if (Current.is(TT_ArraySubscriptLSquare) &&
Expand Down Expand Up @@ -1447,7 +1447,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
CurrentState.QuestionColumn = State.Column;
}
if (!Current.opensScope() && !Current.closesScope() &&
!Current.is(TT_PointerOrReference)) {
Current.isNot(TT_PointerOrReference)) {
State.LowestLevelOnLine =
std::min(State.LowestLevelOnLine, Current.NestingLevel);
}
Expand Down Expand Up @@ -1511,7 +1511,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
// }, a, b, c);
if (Current.isNot(tok::comment) && !Current.ClosesRequiresClause &&
Previous && Previous->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
!Previous->is(TT_DictLiteral) && State.Stack.size() > 1 &&
Previous->isNot(TT_DictLiteral) && State.Stack.size() > 1 &&
!CurrentState.HasMultipleNestedBlocks) {
if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)
for (ParenState &PState : llvm::drop_end(State.Stack))
Expand Down Expand Up @@ -1641,7 +1641,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
// ParameterToInnerFunction));
if (PrecedenceLevel > prec::Unknown)
NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
if (PrecedenceLevel != prec::Conditional && !Current.is(TT_UnaryOperator) &&
if (PrecedenceLevel != prec::Conditional &&
Current.isNot(TT_UnaryOperator) &&
Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) {
NewParenState.StartOfFunctionCall = State.Column;
}
Expand Down Expand Up @@ -2146,7 +2147,7 @@ unsigned ContinuationIndenter::handleEndOfLine(const FormatToken &Current,
static StringRef getEnclosingFunctionName(const FormatToken &Current) {
// Look for: 'function(' or 'function<templates>(' before Current.
auto Tok = Current.getPreviousNonComment();
if (!Tok || !Tok->is(tok::l_paren))
if (!Tok || Tok->isNot(tok::l_paren))
return "";
Tok = Tok->getPreviousNonComment();
if (!Tok)
Expand All @@ -2156,7 +2157,7 @@ static StringRef getEnclosingFunctionName(const FormatToken &Current) {
if (Tok)
Tok = Tok->getPreviousNonComment();
}
if (!Tok || !Tok->is(tok::identifier))
if (!Tok || Tok->isNot(tok::identifier))
return "";
return Tok->TokenText;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/DefinitionBlockSeparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ void DefinitionBlockSeparator::separateBlocks(
InsertReplacement(OpeningLineIndex != 0);
TargetLine = CurrentLine;
TargetToken = TargetLine->First;
while (TargetToken && !TargetToken->is(tok::r_brace))
while (TargetToken && TargetToken->isNot(tok::r_brace))
TargetToken = TargetToken->Next;
if (!TargetToken)
while (I < Lines.size() && !Lines[I]->First->is(tok::r_brace))
while (I < Lines.size() && Lines[I]->First->isNot(tok::r_brace))
++I;
} else if (CurrentLine->First->closesScope()) {
if (OpeningLineIndex > Lines.size())
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ class Formatter : public TokenAnalyzer {
for (const AnnotatedLine *Line : Lines) {
AlignmentDiff += countVariableAlignments(Line->Children);
for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
if (!Tok->is(TT_PointerOrReference))
if (Tok->isNot(TT_PointerOrReference))
continue;
// Don't treat space in `void foo() &&` as evidence.
if (const auto *Prev = Tok->getPreviousNonComment()) {
Expand Down Expand Up @@ -2688,7 +2688,7 @@ class Cleaner : public TokenAnalyzer {
bool DeleteLeft) {
auto NextNotDeleted = [this](const FormatToken &Tok) -> FormatToken * {
for (auto *Res = Tok.Next; Res; Res = Res->Next) {
if (!Res->is(tok::comment) &&
if (Res->isNot(tok::comment) &&
DeletedTokens.find(Res) == DeletedTokens.end()) {
return Res;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ struct FormatToken {
/// Returns \c true if this is a string literal that's like a label,
/// e.g. ends with "=" or ":".
bool isLabelString() const {
if (!is(tok::string_literal))
if (isNot(tok::string_literal))
return false;
StringRef Content = TokenText;
if (Content.startswith("\"") || Content.startswith("'"))
Expand Down
22 changes: 11 additions & 11 deletions clang/lib/Format/FormatTokenLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool FormatTokenLexer::tryMergeNSStringLiteral() {
return false;
auto &At = *(Tokens.end() - 2);
auto &String = *(Tokens.end() - 1);
if (!At->is(tok::at) || !String->is(tok::string_literal))
if (At->isNot(tok::at) || String->isNot(tok::string_literal))
return false;
At->Tok.setKind(tok::string_literal);
At->TokenText = StringRef(At->TokenText.begin(),
Expand All @@ -295,7 +295,7 @@ bool FormatTokenLexer::tryMergeJSPrivateIdentifier() {
return false;
auto &Hash = *(Tokens.end() - 2);
auto &Identifier = *(Tokens.end() - 1);
if (!Hash->is(tok::hash) || !Identifier->is(tok::identifier))
if (Hash->isNot(tok::hash) || Identifier->isNot(tok::identifier))
return false;
Hash->Tok.setKind(tok::identifier);
Hash->TokenText =
Expand Down Expand Up @@ -360,7 +360,7 @@ bool FormatTokenLexer::tryMergeNullishCoalescingEqual() {
auto &NullishCoalescing = *(Tokens.end() - 2);
auto &Equal = *(Tokens.end() - 1);
if (NullishCoalescing->getType() != TT_NullCoalescingOperator ||
!Equal->is(tok::equal)) {
Equal->isNot(tok::equal)) {
return false;
}
NullishCoalescing->Tok.setKind(tok::equal); // no '??=' in clang tokens.
Expand Down Expand Up @@ -399,7 +399,7 @@ bool FormatTokenLexer::tryTransformCSharpForEach() {
if (Tokens.size() < 1)
return false;
auto &Identifier = *(Tokens.end() - 1);
if (!Identifier->is(tok::identifier))
if (Identifier->isNot(tok::identifier))
return false;
if (Identifier->TokenText != "foreach")
return false;
Expand All @@ -414,9 +414,9 @@ bool FormatTokenLexer::tryMergeForEach() {
return false;
auto &For = *(Tokens.end() - 2);
auto &Each = *(Tokens.end() - 1);
if (!For->is(tok::kw_for))
if (For->isNot(tok::kw_for))
return false;
if (!Each->is(tok::identifier))
if (Each->isNot(tok::identifier))
return false;
if (Each->TokenText != "each")
return false;
Expand All @@ -435,7 +435,7 @@ bool FormatTokenLexer::tryTransformTryUsageForC() {
if (Tokens.size() < 2)
return false;
auto &Try = *(Tokens.end() - 2);
if (!Try->is(tok::kw_try))
if (Try->isNot(tok::kw_try))
return false;
auto &Next = *(Tokens.end() - 1);
if (Next->isOneOf(tok::l_brace, tok::colon, tok::hash, tok::comment))
Expand Down Expand Up @@ -511,7 +511,7 @@ bool FormatTokenLexer::tryMergeTokens(ArrayRef<tok::TokenKind> Kinds,
SmallVectorImpl<FormatToken *>::const_iterator First =
Tokens.end() - Kinds.size();
for (unsigned i = 0; i < Kinds.size(); ++i)
if (!First[i]->is(Kinds[i]))
if (First[i]->isNot(Kinds[i]))
return false;

return tryMergeTokens(Kinds.size(), NewType);
Expand Down Expand Up @@ -852,14 +852,14 @@ bool FormatTokenLexer::tryMerge_TMacro() {
if (Tokens.size() < 4)
return false;
FormatToken *Last = Tokens.back();
if (!Last->is(tok::r_paren))
if (Last->isNot(tok::r_paren))
return false;

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

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

FormatToken *Macro = Tokens[Tokens.size() - 4];
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/FormatTokenSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class IndexedTokenSource : public FormatTokenSource {
}

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

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/MacroExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MacroExpander::DefinitionParser {
// Parse the token stream and return the corresponding Definition object.
// Returns an empty definition object with a null-Name on error.
MacroExpander::Definition parse() {
if (!Current->is(tok::identifier))
if (Current->isNot(tok::identifier))
return {};
Def.Name = Current->TokenText;
nextToken();
Expand Down Expand Up @@ -191,7 +191,7 @@ MacroExpander::expand(FormatToken *ID,
auto expandArgument = [&](FormatToken *Tok) -> bool {
// If the current token references a parameter, expand the corresponding
// argument.
if (!Tok->is(tok::identifier) || ExpandedArgs.contains(Tok->TokenText))
if (Tok->isNot(tok::identifier) || ExpandedArgs.contains(Tok->TokenText))
return false;
ExpandedArgs.insert(Tok->TokenText);
auto I = Def.ArgMap.find(Tok->TokenText);
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Format/QualifierAlignmentFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
tooling::Replacements &Fixes, const FormatToken *const Tok,
const std::string &Qualifier, tok::TokenKind QualifierType) {
// We only need to think about streams that begin with a qualifier.
if (!Tok->is(QualifierType))
if (Tok->isNot(QualifierType))
return Tok;
// Don't concern yourself if nothing follows the qualifier.
if (!Tok->Next)
Expand Down Expand Up @@ -367,7 +367,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
tooling::Replacements &Fixes, const FormatToken *const Tok,
const std::string &Qualifier, tok::TokenKind QualifierType) {
// We only need to think about streams that begin with a qualifier.
if (!Tok->is(QualifierType))
if (Tok->isNot(QualifierType))
return Tok;
// Don't concern yourself if nothing preceeds the qualifier.
if (!Tok->getPreviousNonComment())
Expand Down Expand Up @@ -614,7 +614,7 @@ bool LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
bool LeftRightQualifierAlignmentFixer::isPossibleMacro(const FormatToken *Tok) {
if (!Tok)
return false;
if (!Tok->is(tok::identifier))
if (Tok->isNot(tok::identifier))
return false;
if (Tok->TokenText.upper() == Tok->TokenText.str()) {
// T,K,U,V likely could be template arguments
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/SortJavaScriptImports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
nextToken();
if (Current->is(tok::semi))
return true;
if (!Current->is(tok::period))
if (Current->isNot(tok::period))
return false;
nextToken();
}
Expand Down

0 comments on commit 91c4db0

Please sign in to comment.