diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index b23eb549650a7e..386235de1f8f04 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -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))) { @@ -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 && @@ -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; } @@ -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) && @@ -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)) || @@ -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) && @@ -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; } @@ -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) && @@ -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); } @@ -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)) @@ -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; } @@ -2146,7 +2147,7 @@ unsigned ContinuationIndenter::handleEndOfLine(const FormatToken &Current, static StringRef getEnclosingFunctionName(const FormatToken &Current) { // Look for: 'function(' or 'function(' 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) @@ -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; } diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp b/clang/lib/Format/DefinitionBlockSeparator.cpp index 8fb6f55f629edd..319236d3bd618c 100644 --- a/clang/lib/Format/DefinitionBlockSeparator.cpp +++ b/clang/lib/Format/DefinitionBlockSeparator.cpp @@ -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()) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index be0a07f25b946b..339af30e38a7a8 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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()) { @@ -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; } diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 6ce9249c24cdc3..f978ade3ec2ffb 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -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("'")) diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index 4d43796dd70e52..a90ba4af2da840 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -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(), @@ -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 = @@ -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. @@ -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; @@ -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; @@ -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)) @@ -511,7 +511,7 @@ bool FormatTokenLexer::tryMergeTokens(ArrayRef Kinds, SmallVectorImpl::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); @@ -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]; diff --git a/clang/lib/Format/FormatTokenSource.h b/clang/lib/Format/FormatTokenSource.h index ffd2fbbad02ff4..7819244eb7d19a 100644 --- a/clang/lib/Format/FormatTokenSource.h +++ b/clang/lib/Format/FormatTokenSource.h @@ -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; } diff --git a/clang/lib/Format/MacroExpander.cpp b/clang/lib/Format/MacroExpander.cpp index bc98ec4c361fed..5a1cdd884c5e69 100644 --- a/clang/lib/Format/MacroExpander.cpp +++ b/clang/lib/Format/MacroExpander.cpp @@ -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(); @@ -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); diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 86f62dc2eec91a..2f920cdc4db2b5 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -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) @@ -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()) @@ -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 diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index 3ba649d07964ab..9afe85aeed437e 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/clang/lib/Format/SortJavaScriptImports.cpp @@ -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(); } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 2f71cc8dab6ed7..b6b4172818d171 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -148,7 +148,7 @@ class AnnotatingParser { return false; if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 && (!Previous.Previous->MatchingParen || - !Previous.Previous->MatchingParen->is( + Previous.Previous->MatchingParen->isNot( TT_OverloadedOperatorLParen))) { return false; } @@ -302,7 +302,7 @@ class AnnotatingParser { if (OpeningParen.is(TT_OverloadedOperatorLParen)) { // Find the previous kw_operator token. FormatToken *Prev = &OpeningParen; - while (!Prev->is(tok::kw_operator)) { + while (Prev->isNot(tok::kw_operator)) { Prev = Prev->Previous; assert(Prev && "Expect a kw_operator prior to the OperatorLParen!"); } @@ -352,7 +352,7 @@ class AnnotatingParser { Contexts.back().IsExpression = true; } else if (Line.InPPDirective && (!OpeningParen.Previous || - !OpeningParen.Previous->is(tok::identifier))) { + OpeningParen.Previous->isNot(tok::identifier))) { Contexts.back().IsExpression = true; } else if (Contexts[Contexts.size() - 2].CaretFound) { // This is the parameter list of an ObjC block. @@ -1490,7 +1490,7 @@ class AnnotatingParser { } void parseHasInclude() { - if (!CurrentToken || !CurrentToken->is(tok::l_paren)) + if (!CurrentToken || CurrentToken->isNot(tok::l_paren)) return; next(); // '(' parseIncludeDirective(); @@ -1863,7 +1863,8 @@ class AnnotatingParser { } } } else if (Current.is(tok::lessless) && - (!Current.Previous || !Current.Previous->is(tok::kw_operator))) { + (!Current.Previous || + Current.Previous->isNot(tok::kw_operator))) { Contexts.back().IsExpression = true; } else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) { Contexts.back().IsExpression = true; @@ -1891,7 +1892,7 @@ class AnnotatingParser { Contexts.back().CanBeExpression = false; } else if (Current.is(tok::semi) || (Current.is(tok::exclaim) && Current.Previous && - !Current.Previous->is(tok::kw_operator))) { + Current.Previous->isNot(tok::kw_operator))) { // This should be the condition or increment in a for-loop. // But not operator !() (can't use TT_OverloadedOperator here as its not // been annotated yet). @@ -1955,7 +1956,7 @@ class AnnotatingParser { } void determineTokenType(FormatToken &Current) { - if (!Current.is(TT_Unknown)) { + if (Current.isNot(TT_Unknown)) { // The token type is already known. return; } @@ -2043,7 +2044,7 @@ class AnnotatingParser { } } else if (Current.isBinaryOperator() && (!Current.Previous || Current.Previous->isNot(tok::l_square)) && - (!Current.is(tok::greater) && + (Current.isNot(tok::greater) && Style.Language != FormatStyle::LK_TextProto)) { if (Style.isVerilog()) { if (Current.is(tok::lessequal) && Contexts.size() == 1 && @@ -2085,7 +2086,7 @@ class AnnotatingParser { if (AfterParen->isNot(tok::caret)) { if (FormatToken *BeforeParen = Current.MatchingParen->Previous) { if (BeforeParen->is(tok::identifier) && - !BeforeParen->is(TT_TypenameMacro) && + BeforeParen->isNot(TT_TypenameMacro) && BeforeParen->TokenText == BeforeParen->TokenText.upper() && (!BeforeParen->Previous || BeforeParen->Previous->ClosesTemplateDeclaration)) { @@ -2894,7 +2895,7 @@ class ExpressionParser { next(); FormatToken *Start = Current; parse(prec::LogicalOr); - if (!Current || !Current->is(tok::question)) + if (!Current || Current->isNot(tok::question)) return; next(); parse(prec::Assignment); @@ -3182,7 +3183,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current, return false; Next = skipOperatorName(Next); } else { - if (!Current.is(TT_StartOfName) || Current.NestingLevel != 0) + if (Current.isNot(TT_StartOfName) || Current.NestingLevel != 0) return false; for (; Next; Next = Next->Next) { if (Next->is(TT_TemplateOpener) && Next->MatchingParen) { @@ -3195,7 +3196,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current, Next = skipOperatorName(Next->Next); break; } - if (!Next->is(tok::identifier)) + if (Next->isNot(tok::identifier)) return false; } else if (isCppAttribute(IsCpp, *Next)) { Next = Next->MatchingParen; @@ -3210,7 +3211,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current, } // Check whether parameter list can belong to a function declaration. - if (!Next || !Next->is(tok::l_paren) || !Next->MatchingParen) + if (!Next || Next->isNot(tok::l_paren) || !Next->MatchingParen) return false; // If the lines ends with "{", this is likely a function definition. if (Line.Last->is(tok::l_brace)) @@ -3380,7 +3381,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const { if (Parameter->isOneOf(tok::comment, tok::r_brace)) break; if (Parameter->Previous && Parameter->Previous->is(tok::comma)) { - if (!Parameter->Previous->is(TT_CtorInitializerComma) && + if (Parameter->Previous->isNot(TT_CtorInitializerComma) && Parameter->HasUnescapedNewline) { Parameter->MustBreakBefore = true; } @@ -3713,7 +3714,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, } if (Right.is(tok::lessless)) { // Breaking at a << is really cheap. - if (!Left.is(tok::r_paren) || Right.OperatorIndex > 0) { + if (Left.isNot(tok::r_paren) || Right.OperatorIndex > 0) { // Slightly prefer to break before the first one in log-like statements. return 2; } @@ -3837,7 +3838,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return false; } if (Left.is(tok::colon)) - return !Left.is(TT_ObjCMethodExpr); + return Left.isNot(TT_ObjCMethodExpr); if (Left.is(tok::coloncolon)) return false; if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less)) { @@ -3865,7 +3866,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return true; FormatToken *TokenBeforeMatchingParen = Left.MatchingParen->getPreviousNonComment(); - if (!TokenBeforeMatchingParen || !Left.is(TT_TypeDeclarationParen)) + if (!TokenBeforeMatchingParen || Left.isNot(TT_TypeDeclarationParen)) return true; } // Add a space if the previous token is a pointer qualifier or the closing @@ -3893,7 +3894,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, (Left.NestingLevel == 1 && startsWithInitStatement(Line))))); } if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) && - (!Left.is(TT_PointerOrReference) || + (Left.isNot(TT_PointerOrReference) || (getTokenPointerOrReferenceAlignment(Left) != FormatStyle::PAS_Right && !Line.IsMultiVariableDeclStmt))) { return true; @@ -3916,7 +3917,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, // S::foo() & noexcept/requires if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final, tok::kw_noexcept, TT_RequiresClause) && - !Right.is(TT_StartOfName)) { + Right.isNot(TT_StartOfName)) { return true; } // & { @@ -3961,7 +3962,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return false; if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) { const FormatToken *Previous = &Left; - while (Previous && !Previous->is(tok::kw_operator)) { + while (Previous && Previous->isNot(tok::kw_operator)) { if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) { Previous = Previous->getPreviousNonComment(); continue; @@ -4033,7 +4034,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, TT_DesignatedInitializerLSquare, TT_StructuredBindingLSquare, TT_AttributeSquare) && !Left.isOneOf(tok::numeric_constant, TT_DictLiteral) && - !(!Left.is(tok::r_square) && Style.SpaceBeforeSquareBrackets && + !(Left.isNot(tok::r_square) && Style.SpaceBeforeSquareBrackets && Right.is(TT_ArraySubscriptLSquare))) { return false; } @@ -4428,7 +4429,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, (Left.is(Keywords.kw_of) && Left.Previous && (Left.Previous->is(tok::identifier) || Left.Previous->isOneOf(tok::r_square, tok::r_brace)))) && - (!Left.Previous || !Left.Previous->is(tok::period))) { + (!Left.Previous || Left.Previous->isNot(tok::period))) { return true; } if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous && @@ -4503,7 +4504,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return false; } // Add space after a delay. - if (!Right.is(tok::semi) && + if (Right.isNot(tok::semi) && (Left.endsSequence(tok::numeric_constant, Keywords.kw_verilogHash) || Left.endsSequence(tok::numeric_constant, Keywords.kw_verilogHashHash) || @@ -4578,7 +4579,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, Left.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow)) { return true; } - if (Left.is(tok::comma) && !Right.is(TT_OverloadedOperatorLParen) && + if (Left.is(tok::comma) && Right.isNot(TT_OverloadedOperatorLParen) && // In an unexpanded macro call we only find the parentheses and commas // in a line; the commas and closing parenthesis do not require a space. (Left.Children.empty() || !Left.MacroParent)) { @@ -4636,7 +4637,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return true; } if (Left.is(TT_UnaryOperator)) { - if (!Right.is(tok::l_paren)) { + if (Right.isNot(tok::l_paren)) { // The alternative operators for ~ and ! are "compl" and "not". // If they are used instead, we do not want to combine them with // the token to the right, unless that is a left paren. @@ -4719,9 +4720,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, Right.isOneOf(tok::amp, tok::ampamp)) { return getTokenReferenceAlignment(Right) != FormatStyle::PAS_Left; } - if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) || + if ((Right.is(TT_BinaryOperator) && Left.isNot(tok::l_paren)) || (Left.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && - !Right.is(tok::r_paren))) { + Right.isNot(tok::r_paren))) { return true; } if (Right.is(TT_TemplateOpener) && Left.is(tok::r_paren) && @@ -5137,7 +5138,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, // We ensure elsewhere that extensions are always on their own line. if ((Style.Language == FormatStyle::LK_Proto || Style.Language == FormatStyle::LK_TextProto) && - Right.is(TT_SelectorName) && !Right.is(tok::r_square) && Right.Next) { + Right.is(TT_SelectorName) && Right.isNot(tok::r_square) && Right.Next) { // Keep `@submessage` together in: // @submessage { key: value } if (Left.is(tok::at)) @@ -5261,7 +5262,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, // is: 'name', // ... // }); - if (!Next || !Next->is(tok::colon)) + if (!Next || Next->isNot(tok::colon)) return false; } if (Left.is(Keywords.kw_in)) @@ -5308,7 +5309,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, if (Left.Tok.getObjCKeywordID() == tok::objc_interface) return false; if (Left.isOneOf(TT_JavaAnnotation, TT_LeadingJavaAnnotation)) - return !Right.is(tok::l_paren); + return Right.isNot(tok::l_paren); if (Right.is(TT_PointerOrReference)) { return Line.IsMultiVariableDeclStmt || (getTokenPointerOrReferenceAlignment(Right) == @@ -5341,7 +5342,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, return Style.BreakInheritanceList == FormatStyle::BILS_AfterColon; if (Right.is(TT_InheritanceColon)) return Style.BreakInheritanceList != FormatStyle::BILS_AfterColon; - if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) && + if (Right.is(TT_ObjCMethodExpr) && Right.isNot(tok::r_square) && Left.isNot(TT_SelectorName)) { return true; } @@ -5486,7 +5487,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, if (Right.is(tok::kw___attribute) || (Right.is(tok::l_square) && Right.is(TT_AttributeSquare))) { - return !Left.is(TT_AttributeSquare); + return Left.isNot(TT_AttributeSquare); } if (Left.is(tok::identifier) && Right.is(tok::string_literal)) @@ -5548,8 +5549,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, tok::colon, tok::l_square, tok::at) || (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_const)) || - (Left.is(tok::l_paren) && !Right.is(tok::r_paren)) || - (Left.is(TT_TemplateOpener) && !Right.is(TT_TemplateCloser)); + (Left.is(tok::l_paren) && Right.isNot(tok::r_paren)) || + (Left.is(TT_TemplateOpener) && Right.isNot(TT_TemplateCloser)); } void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) const { diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 52519145279cce..8f0b05ecb91d67 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -405,7 +405,8 @@ class LineJoiner { openingLine == I[i + 1]->MatchingOpeningBlockLineIndex; i++, --openingLine) { // No space between consecutive braces. - I[i + 1]->First->SpacesRequiredBefore = !I[i]->Last->is(tok::r_brace); + I[i + 1]->First->SpacesRequiredBefore = + I[i]->Last->isNot(tok::r_brace); // Indent like the outer-most namespace. IndentTracker.nextLine(*I[i + 1]); @@ -622,12 +623,12 @@ class LineJoiner { } Limit = limitConsideringMacros(I + 1, E, Limit); AnnotatedLine &Line = **I; - if (!Line.First->is(tok::kw_do) && !Line.First->is(tok::kw_else) && - !Line.Last->is(tok::kw_else) && Line.Last->isNot(tok::r_paren)) { + if (Line.First->isNot(tok::kw_do) && Line.First->isNot(tok::kw_else) && + Line.Last->isNot(tok::kw_else) && Line.Last->isNot(tok::r_paren)) { return 0; } // Only merge `do while` if `do` is the only statement on the line. - if (Line.First->is(tok::kw_do) && !Line.Last->is(tok::kw_do)) + if (Line.First->is(tok::kw_do) && Line.Last->isNot(tok::kw_do)) return 0; if (1 + I[1]->Last->TotalLength > Limit) return 0; @@ -754,21 +755,21 @@ class LineJoiner { if (!Style.AllowShortIfStatementsOnASingleLine && Line.First->isOneOf(tok::kw_if, tok::kw_else) && !Style.BraceWrapping.AfterControlStatement && - !I[1]->First->is(tok::r_brace)) { + I[1]->First->isNot(tok::r_brace)) { return 0; } if (!Style.AllowShortIfStatementsOnASingleLine && Line.First->isOneOf(tok::kw_if, tok::kw_else) && Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_Always && - I + 2 != E && !I[2]->First->is(tok::r_brace)) { + I + 2 != E && I[2]->First->isNot(tok::r_brace)) { return 0; } if (!Style.AllowShortLoopsOnASingleLine && Line.First->isOneOf(tok::kw_while, tok::kw_do, tok::kw_for, TT_ForEachMacro) && !Style.BraceWrapping.AfterControlStatement && - !I[1]->First->is(tok::r_brace)) { + I[1]->First->isNot(tok::r_brace)) { return 0; } if (!Style.AllowShortLoopsOnASingleLine && @@ -776,7 +777,7 @@ class LineJoiner { TT_ForEachMacro) && Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_Always && - I + 2 != E && !I[2]->First->is(tok::r_brace)) { + I + 2 != E && I[2]->First->isNot(tok::r_brace)) { return 0; } // FIXME: Consider an option to allow short exception handling clauses on @@ -886,7 +887,7 @@ class LineJoiner { SmallVectorImpl::const_iterator E, unsigned Limit) { if (I[0]->InPPDirective && I + 1 != E && - !I[1]->First->HasUnescapedNewline && !I[1]->First->is(tok::eof)) { + !I[1]->First->HasUnescapedNewline && I[1]->First->isNot(tok::eof)) { return Limit < 2 ? 0 : Limit - 2; } return Limit; @@ -1494,8 +1495,10 @@ static auto computeNewlines(const AnnotatedLine &Line, previousToken = PreviousLine->Last->getPreviousNonComment(); else previousToken = PreviousLine->Last; - if ((!previousToken || !previousToken->is(tok::l_brace)) && Newlines <= 1) + if ((!previousToken || previousToken->isNot(tok::l_brace)) && + Newlines <= 1) { Newlines = 2; + } } break; } } diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index a89265a858f405..5a82b200055a87 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -394,7 +394,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace, ParseDefault(); continue; } - if (CanContainBracedList && !FormatTok->is(TT_MacroBlockBegin) && + if (CanContainBracedList && FormatTok->isNot(TT_MacroBlockBegin) && tryToParseBracedList()) { continue; } @@ -615,7 +615,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { LBraceStack.pop_back(); break; case tok::identifier: - if (!Tok->is(TT_StatementMacro)) + if (Tok->isNot(TT_StatementMacro)) break; [[fallthrough]]; case tok::at: @@ -799,8 +799,8 @@ FormatToken *UnwrappedLineParser::parseBlock( if (eof()) return IfLBrace; - if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd) - : !FormatTok->is(tok::r_brace)) { + if (MacroBlock ? FormatTok->isNot(TT_MacroBlockEnd) + : FormatTok->isNot(tok::r_brace)) { Line->Level = InitialLevel; FormatTok->setBlockKind(BK_Block); return IfLBrace; @@ -1080,7 +1080,7 @@ void UnwrappedLineParser::parsePPIf(bool IfDef) { bool MaybeIncludeGuard = IfNDef; if (IncludeGuard == IG_Inited && MaybeIncludeGuard) { for (auto &Line : Lines) { - if (!Line.Tokens.front().Tok->is(tok::comment)) { + if (Line.Tokens.front().Tok->isNot(tok::comment)) { MaybeIncludeGuard = false; IncludeGuard = IG_Rejected; break; @@ -1612,7 +1612,7 @@ void UnwrappedLineParser::parseStructuralElement( nextToken(); if (FormatTok->is(tok::kw_public)) nextToken(); - if (!FormatTok->is(tok::string_literal)) + if (FormatTok->isNot(tok::string_literal)) return; nextToken(); if (FormatTok->is(tok::semi)) @@ -1887,8 +1887,9 @@ void UnwrappedLineParser::parseStructuralElement( // a new unwrapped line, so they are special cased below. size_t TokenCount = Line->Tokens.size(); if (Style.isJavaScript() && FormatTok->is(Keywords.kw_function) && - (TokenCount > 1 || (TokenCount == 1 && !Line->Tokens.front().Tok->is( - Keywords.kw_async)))) { + (TokenCount > 1 || + (TokenCount == 1 && + Line->Tokens.front().Tok->isNot(Keywords.kw_async)))) { tryToParseJSFunction(); break; } @@ -2872,7 +2873,7 @@ void UnwrappedLineParser::parseTryCatch() { FormatTok->is(tok::l_brace)) { do { nextToken(); - } while (!FormatTok->is(tok::r_brace)); + } while (FormatTok->isNot(tok::r_brace)); nextToken(); } @@ -2895,7 +2896,7 @@ void UnwrappedLineParser::parseTryCatch() { addUnwrappedLine(); else NeedsUnwrappedLine = true; - } else if (!FormatTok->is(tok::kw_catch)) { + } else if (FormatTok->isNot(tok::kw_catch)) { // The C++ standard requires a compound-statement after a try. // If there's none, we try to assume there's a structuralElement // and try to continue. @@ -3109,7 +3110,7 @@ void UnwrappedLineParser::parseDoWhile() { parseLoopBody(/*KeepBraces=*/true, Style.BraceWrapping.BeforeWhile); // FIXME: Add error handling. - if (!FormatTok->is(tok::kw_while)) { + if (FormatTok->isNot(tok::kw_while)) { addUnwrappedLine(); return; } @@ -3260,7 +3261,7 @@ void UnwrappedLineParser::parseAccessSpecifier() { if (FormatTok->is(tok::colon)) { nextToken(); addUnwrappedLine(); - } else if (!FormatTok->is(tok::coloncolon) && + } else if (FormatTok->isNot(tok::coloncolon) && !isCOperatorFollowingVar(FormatTok->Tok.getKind())) { // Not a variable name nor namespace name. addUnwrappedLine(); @@ -3574,7 +3575,7 @@ void UnwrappedLineParser::parseConstraintExpression() { case tok::kw_reinterpret_cast: case tok::kw_dynamic_cast: nextToken(); - if (!FormatTok->is(tok::less)) + if (FormatTok->isNot(tok::less)) return; nextToken(); @@ -3746,7 +3747,7 @@ bool UnwrappedLineParser::tryToParseSimpleAttribute() { ScopedTokenPosition AutoPosition(Tokens); FormatToken *Tok = Tokens->getNextToken(); // We already read the first [ check for the second. - if (!Tok->is(tok::l_square)) + if (Tok->isNot(tok::l_square)) return false; // Double check that the attribute is just something // fairly simple. @@ -3758,7 +3759,7 @@ bool UnwrappedLineParser::tryToParseSimpleAttribute() { if (Tok->is(tok::eof)) return false; Tok = Tokens->getNextToken(); - if (!Tok->is(tok::r_square)) + if (Tok->isNot(tok::r_square)) return false; Tok = Tokens->getNextToken(); if (Tok->is(tok::semi)) @@ -3776,7 +3777,7 @@ void UnwrappedLineParser::parseJavaEnumBody() { unsigned StoredPosition = Tokens->getPosition(); bool IsSimple = true; FormatToken *Tok = Tokens->getNextToken(); - while (!Tok->is(tok::eof)) { + while (Tok->isNot(tok::eof)) { if (Tok->is(tok::r_brace)) break; if (Tok->isOneOf(tok::l_brace, tok::semi)) { @@ -4165,7 +4166,7 @@ void UnwrappedLineParser::parseVerilogHierarchyIdentifier() { } void UnwrappedLineParser::parseVerilogSensitivityList() { - if (!FormatTok->is(tok::at)) + if (FormatTok->isNot(tok::at)) return; nextToken(); // A block event expression has 2 at signs. @@ -4768,7 +4769,7 @@ void UnwrappedLineParser::readToken(int LevelDifference) { } } - if (!FormatTok->is(tok::comment)) { + if (FormatTok->isNot(tok::comment)) { distributeComments(Comments, FormatTok); Comments.clear(); return; @@ -4798,7 +4799,7 @@ UnwrappedLineParser::parseMacroCall() { std::optional, 1>> Args; assert(Line->Tokens.empty()); nextToken(); - if (!FormatTok->is(tok::l_paren)) + if (FormatTok->isNot(tok::l_paren)) return Args; unsigned Position = Tokens->getPosition(); FormatToken *Tok = FormatTok; diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 61e59d042b14c1..04048aedb3e392 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -590,14 +590,14 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches, // A new line starts, re-initialize line status tracking bools. // Keep the match state if a string literal is continued on this line. - if (i == 0 || !Changes[i].Tok->is(tok::string_literal) || - !Changes[i - 1].Tok->is(tok::string_literal)) { + if (i == 0 || Changes[i].Tok->isNot(tok::string_literal) || + Changes[i - 1].Tok->isNot(tok::string_literal)) { FoundMatchOnLine = false; } LineIsComment = true; } - if (!Changes[i].Tok->is(tok::comment)) + if (Changes[i].Tok->isNot(tok::comment)) LineIsComment = false; if (Changes[i].Tok->is(tok::comma)) { @@ -731,10 +731,10 @@ void WhitespaceManager::alignConsecutiveMacros() { SpacesRequiredBefore = 0; } - if (!Current || !Current->is(tok::identifier)) + if (!Current || Current->isNot(tok::identifier)) return false; - if (!Current->Previous || !Current->Previous->is(tok::pp_define)) + if (!Current->Previous || Current->Previous->isNot(tok::pp_define)) return false; // For a macro function, 0 spaces are required between the @@ -781,7 +781,7 @@ void WhitespaceManager::alignConsecutiveMacros() { LineIsComment = true; } - if (!Changes[I].Tok->is(tok::comment)) + if (Changes[I].Tok->isNot(tok::comment)) LineIsComment = false; if (!AlignMacrosMatches(Changes[I]))