Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ bool ContinuationIndenter::canBreak(const LineState &State) {

// If binary operators are moved to the next line (including commas for some
// styles of constructor initializers), that's always ok.
if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&
if (Current.isNoneOf(TT_BinaryOperator, tok::comma) &&
// Allow breaking opening brace of lambdas (when passed as function
// arguments) to a new line when BeforeLambdaBody brace wrapping is
// enabled.
Expand Down Expand Up @@ -445,7 +445,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
(!Style.BreakBeforeTernaryOperators &&
Previous.is(TT_ConditionalExpr))) &&
CurrentState.BreakBeforeParameter && !Current.isTrailingComment() &&
!Current.isOneOf(tok::r_paren, tok::r_brace)) {
Current.isNoneOf(tok::r_paren, tok::r_brace)) {
return true;
}
if (CurrentState.IsChainedConditional &&
Expand Down Expand Up @@ -523,9 +523,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
if (Style.AlwaysBreakBeforeMultilineStrings &&
(NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
Previous.is(tok::comma) || Current.NestingLevel < 2) &&
!Previous.isOneOf(tok::kw_return, tok::lessless, tok::at,
Previous.isNoneOf(tok::kw_return, tok::lessless, tok::at,
Keywords.kw_dollar) &&
!Previous.isOneOf(TT_InlineASMColon, TT_ConditionalExpr) &&
Previous.isNoneOf(TT_InlineASMColon, TT_ConditionalExpr) &&
nextIsMultilineString(State)) {
return true;
}
Expand Down Expand Up @@ -648,7 +648,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
// into the ColumnLimit, they are checked here in the ContinuationIndenter.
if (Style.ColumnLimit != 0 && Previous.is(BK_Block) &&
Previous.is(tok::l_brace) &&
!Current.isOneOf(tok::r_brace, tok::comment)) {
Current.isNoneOf(tok::r_brace, tok::comment)) {
return true;
}

Expand Down Expand Up @@ -752,7 +752,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
return false;

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

if (DisallowLineBreaks())
Expand Down Expand Up @@ -835,15 +835,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
return Tok.is(tok::l_brace) && Tok.isNot(BK_Block) &&
Style.Cpp11BracedListStyle;
};
if (!Tok.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
if (Tok.isNoneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
!IsStartOfBracedList()) {
return false;
}
if (!Tok.Previous)
return true;
if (Tok.Previous->isIf())
return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
return Tok.Previous->isNoneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
tok::kw_switch) &&
!(Style.isJavaScript() && Tok.Previous->is(Keywords.kw_await));
};
Expand Down Expand Up @@ -882,8 +882,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
Tok.isOneOf(tok::ellipsis, Keywords.kw_await))) {
return true;
}
const auto *Previous = Tok.Previous;
if (!Previous || (!Previous->isOneOf(TT_FunctionDeclarationLParen,
if (const auto *Previous = Tok.Previous;
!Previous || (Previous->isNoneOf(TT_FunctionDeclarationLParen,
TT_LambdaDefinitionLParen) &&
!IsFunctionCallParen(*Previous))) {
return true;
Expand Down Expand Up @@ -920,9 +920,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
// align the commas with the opening paren.
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
!CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
Previous.isNot(TT_TableGenDAGArgOpener) &&
Previous.isNot(TT_TableGenDAGArgOpenerToBreak) &&
Previous.isNoneOf(TT_ObjCMethodExpr, TT_RequiresClause,
TT_TableGenDAGArgOpener,
TT_TableGenDAGArgOpenerToBreak) &&
!(Current.MacroParent && Previous.MacroParent) &&
(Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen)) &&
Expand Down Expand Up @@ -962,7 +962,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
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) &&
P->isNoneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
P->getPrecedence() != prec::Assignment &&
P->getPrecedence() != prec::Relational &&
P->getPrecedence() != prec::Spaceship) {
Expand Down Expand Up @@ -992,7 +992,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
// parameter, i.e. let nested calls have a continuation indent.
CurrentState.LastSpace = State.Column;
CurrentState.NestedBlockIndent = State.Column;
} else if (!Current.isOneOf(tok::comment, tok::caret) &&
} else if (Current.isNoneOf(tok::comment, tok::caret) &&
((Previous.is(tok::comma) &&
Previous.isNot(TT_OverloadedOperator)) ||
(Previous.is(tok::colon) && Previous.is(TT_ObjCMethodExpr)))) {
Expand Down Expand Up @@ -1099,7 +1099,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
if (Current.isNot(TT_LambdaArrow) &&
(!Style.isJavaScript() || Current.NestingLevel != 0 ||
!PreviousNonComment || PreviousNonComment->isNot(tok::equal) ||
!Current.isOneOf(Keywords.kw_async, Keywords.kw_function))) {
Current.isNoneOf(Keywords.kw_async, Keywords.kw_function))) {
CurrentState.NestedBlockIndent = State.Column;
}

Expand Down Expand Up @@ -1239,11 +1239,11 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
}

if (PreviousNonComment &&
!PreviousNonComment->isOneOf(tok::comma, tok::colon, tok::semi) &&
PreviousNonComment->isNoneOf(tok::comma, tok::colon, tok::semi) &&
((PreviousNonComment->isNot(TT_TemplateCloser) &&
!PreviousNonComment->ClosesRequiresClause) ||
Current.NestingLevel != 0) &&
!PreviousNonComment->isOneOf(
PreviousNonComment->isNoneOf(
TT_BinaryOperator, TT_FunctionAnnotationRParen, TT_JavaAnnotation,
TT_LeadingJavaAnnotation) &&
Current.isNot(TT_BinaryOperator) && !PreviousNonComment->opensScope() &&
Expand Down Expand Up @@ -1281,8 +1281,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
bool AllowAllConstructorInitializersOnNextLine =
Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine ||
Style.PackConstructorInitializers == FormatStyle::PCIS_NextLineOnly;
if (!(Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) ||
PreviousIsBreakingCtorInitializerColon) ||
if ((Previous.isNoneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) &&
!PreviousIsBreakingCtorInitializerColon) ||
(!Style.AllowAllParametersOfDeclarationOnNextLine &&
State.Line->MustBeDeclaration) ||
(!Style.AllowAllArgumentsOnNextLine &&
Expand Down Expand Up @@ -1576,7 +1576,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
if (Previous.is(tok::r_paren) &&
Previous.isNot(TT_TableGenDAGArgOperatorToBreak) &&
!Current.isBinaryOperator() &&
!Current.isOneOf(tok::colon, tok::comment)) {
Current.isNoneOf(tok::colon, tok::comment)) {
return ContinuationIndent;
}
if (Current.is(TT_ProtoExtensionLSquare))
Expand All @@ -1591,7 +1591,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
NextNonComment->SpacesRequiredBefore;
}
if (CurrentState.Indent == State.FirstIndent && PreviousNonComment &&
!PreviousNonComment->isOneOf(tok::r_brace, TT_CtorInitializerComma)) {
PreviousNonComment->isNoneOf(tok::r_brace, TT_CtorInitializerComma)) {
// Ensure that we fall back to the continuation indent width instead of
// just flushing continuations left.
return CurrentState.Indent + Style.ContinuationIndentWidth;
Expand Down Expand Up @@ -1734,7 +1734,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
}
if (Previous && (Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) ||
(Previous->isOneOf(tok::l_paren, tok::comma, tok::colon) &&
!Previous->isOneOf(TT_DictLiteral, TT_ObjCMethodExpr,
Previous->isNoneOf(TT_DictLiteral, TT_ObjCMethodExpr,
TT_CtorInitializerColon)))) {
CurrentState.NestedBlockInlined =
!Newline && hasNestedBlockInlined(Previous, Current, Style);
Expand All @@ -1758,7 +1758,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
State.StartOfStringLiteral = State.Column + 1;
} else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
State.StartOfStringLiteral = State.Column;
} else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
} else if (Current.isNoneOf(tok::comment, tok::identifier, tok::hash) &&
!Current.isStringLiteral()) {
State.StartOfStringLiteral = 0;
}
Expand Down Expand Up @@ -2057,7 +2057,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
// array literals as these follow different indentation rules.
bool NoLineBreak =
Current.Children.empty() &&
!Current.isOneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&
Current.isNoneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&
(CurrentState.NoLineBreak || CurrentState.NoLineBreakInOperand ||
(Current.is(TT_TemplateOpener) &&
CurrentState.ContainsUnwrappedBuilder));
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,7 @@ class BracesRemover : public TokenAnalyzer {
const auto *NextLine = I + 1 == End ? nullptr : I[1];
for (const auto *Token = Line->First; Token && !Token->Finalized;
Token = Token->Next) {
if (!Token->Optional || !Token->isOneOf(tok::l_brace, tok::r_brace))
if (!Token->Optional || Token->isNoneOf(tok::l_brace, tok::r_brace))
continue;
auto *Next = Token->Next;
assert(Next || Token == Line->Last);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/FormatToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
// Ensure that we start on the opening brace.
const FormatToken *LBrace =
State.NextToken->Previous->getPreviousNonComment();
if (!LBrace || !LBrace->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
if (!LBrace || LBrace->isNoneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
LBrace->is(BK_Block) || LBrace->is(TT_DictLiteral) ||
LBrace->Next->is(TT_DesignatedInitializerPeriod)) {
return 0;
Expand Down Expand Up @@ -177,7 +177,7 @@ static unsigned CodePointsBetween(const FormatToken *Begin,
void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
// FIXME: At some point we might want to do this for other lists, too.
if (!Token->MatchingParen ||
!Token->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
Token->isNoneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ struct FormatToken {
return is(K1) || isOneOf(K2, Ks...);
}
template <typename T> bool isNot(T Kind) const { return !is(Kind); }
template <typename... Ts> bool isNoneOf(Ts... Ks) const {
return !isOneOf(Ks...);
}

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

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/FormatTokenLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ void FormatTokenLexer::tryParseJavaTextBlock() {
// its text if successful.
void FormatTokenLexer::tryParseJSRegexLiteral() {
FormatToken *RegexToken = Tokens.back();
if (!RegexToken->isOneOf(tok::slash, tok::slashequal))
if (RegexToken->isNoneOf(tok::slash, tok::slashequal))
return;

FormatToken *Prev = nullptr;
Expand Down Expand Up @@ -1041,7 +1041,7 @@ void FormatTokenLexer::handleTemplateStrings() {

void FormatTokenLexer::tryParsePythonComment() {
FormatToken *HashToken = Tokens.back();
if (!HashToken->isOneOf(tok::hash, tok::hashhash))
if (HashToken->isNoneOf(tok::hash, tok::hashhash))
return;
// Turn the remainder of this line into a comment.
const char *CommentBegin =
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/MacroExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class MacroExpander::DefinitionParser {
}

bool parseExpansion() {
if (!Current->isOneOf(tok::equal, tok::eof))
if (Current->isNoneOf(tok::equal, tok::eof))
return false;
if (Current->is(tok::equal))
nextToken();
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/NamespaceEndCommentsFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::string computeName(const FormatToken *NamespaceTok) {
// and closing parenthesis or comma.
assert(Tok && Tok->is(tok::l_paren) && "expected an opening parenthesis");
Tok = Tok->getNextNonComment();
while (Tok && !Tok->isOneOf(tok::r_paren, tok::comma)) {
while (Tok && Tok->isNoneOf(tok::r_paren, tok::comma)) {
name += Tok->TokenText;
Tok = Tok->getNextNonComment();
}
Expand All @@ -85,7 +85,7 @@ std::string computeName(const FormatToken *NamespaceTok) {
// one token before that up until the '{'. A '(' might be a macro with
// arguments.
const FormatToken *FirstNSTok = nullptr;
while (Tok && !Tok->isOneOf(tok::l_brace, tok::coloncolon, tok::l_paren)) {
while (Tok && Tok->isNoneOf(tok::l_brace, tok::coloncolon, tok::l_paren)) {
if (FirstNSTok)
FirstNSName += FirstNSTok->TokenText;
FirstNSTok = Tok;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
}

// Most attributes look like identifiers, but `class` is a keyword.
if (!Tok->isOneOf(tok::identifier, tok::kw_class)) {
if (Tok->isNoneOf(tok::identifier, tok::kw_class)) {
// If we hit any other kind of token, just bail.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/QualifierAlignmentFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(

// Don't change declarations such as
// `foo(struct Foo const a);` -> `foo(struct Foo const a);`
if (!Previous || !Previous->isOneOf(tok::kw_struct, tok::kw_class)) {
if (!Previous || Previous->isNoneOf(tok::kw_struct, tok::kw_class)) {
insertQualifierBefore(SourceMgr, Fixes, TypeToken, Qualifier);
removeToken(SourceMgr, Fixes, Tok);
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/SortJavaScriptImports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
// for grammar EBNF (production ModuleItem).
bool parseModuleReference(const AdditionalKeywords &Keywords,
JsModuleReference &Reference) {
if (!Current || !Current->isOneOf(Keywords.kw_import, tok::kw_export))
if (!Current || Current->isNoneOf(Keywords.kw_import, tok::kw_export))
return false;
Reference.IsExport = Current->is(tok::kw_export);

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

if (!Current->isOneOf(tok::r_brace, tok::comma))
if (Current->isNoneOf(tok::r_brace, tok::comma))
return false;
}
Reference.SymbolsEnd = Current->Tok.getLocation();
Expand Down
Loading