[clang] [clang-format][NFC] Introduce isNotOneOf (PR #161021)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 28 13:49:06 PDT 2025


HazardyKnusperkeks wrote:

> Running `grep` in `clang/lib/Format/` gives the following (likely) missed ones:
> 
> ```
> $ grep -nw isOneOf *.cpp | grep \!
> ContinuationIndenter.cpp:371:  if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&
> ContinuationIndenter.cpp:448:      !Current.isOneOf(tok::r_paren, tok::r_brace)) {
> ContinuationIndenter.cpp:651:      !Current.isOneOf(tok::r_brace, tok::comment)) {
> ContinuationIndenter.cpp:886:    if (!Previous || (!Previous->isOneOf(TT_FunctionDeclarationLParen,
> ContinuationIndenter.cpp:965:      !P->isOneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
> ContinuationIndenter.cpp:995:  } else if (!Current.isOneOf(tok::comment, tok::caret) &&
> ContinuationIndenter.cpp:1102:       !Current.isOneOf(Keywords.kw_async, Keywords.kw_function))) {
> ContinuationIndenter.cpp:1594:      !PreviousNonComment->isOneOf(tok::r_brace, TT_CtorInitializerComma)) {
> ContinuationIndenter.cpp:1761:  } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
> ContinuationIndenter.cpp:2060:      !Current.isOneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&
> Format.cpp:2438:        if (!Token->Optional || !Token->isOneOf(tok::l_brace, tok::r_brace))
> FormatToken.cpp:111:  if (!LBrace || !LBrace->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
> FormatToken.cpp:180:      !Token->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
> FormatTokenLexer.cpp:736:  if (!RegexToken->isOneOf(tok::slash, tok::slashequal))
> FormatTokenLexer.cpp:1044:  if (!HashToken->isOneOf(tok::hash, tok::hashhash))
> MacroExpander.cpp:89:    if (!Current->isOneOf(tok::equal, tok::eof))
> NamespaceEndCommentsFixer.cpp:73:    while (Tok && !Tok->isOneOf(tok::r_paren, tok::comma)) {
> ObjCPropertyAttributeOrderFixer.cpp:64:    if (!Tok->isOneOf(tok::identifier, tok::kw_class)) {
> QualifierAlignmentFixer.cpp:511:    if (!Previous || !Previous->isOneOf(tok::kw_struct, tok::kw_class)) {
> SortJavaScriptImports.cpp:442:    if (!Current || !Current->isOneOf(Keywords.kw_import, tok::kw_export))
> SortJavaScriptImports.cpp:573:      if (!Current->isOneOf(tok::r_brace, tok::comma))
> TokenAnnotator.cpp:206:              (!Next || !Next->isOneOf(tok::l_paren, tok::l_brace))) {
> TokenAnnotator.cpp:254:      if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
> TokenAnnotator.cpp:707:        !CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
> TokenAnnotator.cpp:1342:             !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) ||
> TokenAnnotator.cpp:1419:             Token && !Token->isOneOf(tok::semi, tok::l_paren);
> TokenAnnotator.cpp:1570:          !Tok->isOneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen)) {
> TokenAnnotator.cpp:1736:            (!Next || !Next->isOneOf(tok::identifier, tok::string_literal) ||
> TokenAnnotator.cpp:1737:             !Next->Next || !Next->Next->isOneOf(tok::colon, tok::question))) {
> TokenAnnotator.cpp:1804:                   (!Next || !Next->isOneOf(tok::colon, tok::l_brace))) {
> TokenAnnotator.cpp:2238:          return !Current.Previous->Previous->isOneOf(tok::kw_typename,
> TokenAnnotator.cpp:2274:             !Previous->Previous->isOneOf(tok::comma, tok::semi);
> TokenAnnotator.cpp:2438:               !Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
> TokenAnnotator.cpp:2666:             !PreviousNotConst->MatchingParen->Previous->isOneOf(
> TokenAnnotator.cpp:2926:        !AfterRParen->Next->isOneOf(tok::identifier, tok::numeric_constant)) {
> TokenAnnotator.cpp:3137:      return !token || token->isOneOf(tok::amp, tok::period, tok::arrow,
> TokenAnnotator.cpp:3865:        !Previous.isOneOf(tok::kw_return, tok::kw_co_return)) {
> TokenAnnotator.cpp:4583:      !Right.isOneOf(tok::semi, tok::r_paren)) {
> TokenAnnotator.cpp:4660:    return !Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
> TokenAnnotator.cpp:4733:    return !BeforeLeft->isOneOf(tok::l_paren, tok::l_square);
> TokenAnnotator.cpp:4898:    if (!BeforeLeft || !BeforeLeft->isOneOf(tok::period, tok::arrow)) {
> TokenAnnotator.cpp:5303:         !Right.isOneOf(tok::r_paren, tok::semi)) ||
> TokenAnnotator.cpp:5352:        !(Left.isOneOf(Keywords.kw_assign, Keywords.kw_unique) ||
> TokenAnnotator.cpp:5571:    return !Left.isOneOf(tok::amp, tok::ampamp) ||
> TokenAnnotator.cpp:5621:         !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
> TokenAnnotator.cpp:5690:        !Line.First->isOneOf(Keywords.kw_var, Keywords.kw_let)) {
> TokenAnnotator.cpp:5835:    return !Left.isOneOf(BK_BracedInit, TT_CtorInitializerColon) &&
> TokenAnnotator.cpp:5877:      return !Right.isOneOf(tok::semi, tok::l_brace);
> TokenAnnotator.cpp:6004:      !Right.isOneOf(TT_LeadingJavaAnnotation, tok::l_paren) &&
> TokenAnnotator.cpp:6382:  if (Left.is(tok::equal) && !Right.isOneOf(tok::kw_default, tok::kw_delete) &&
> TokenAnnotator.cpp:6452:      !Left.isOneOf(tok::arrowstar, tok::lessless) &&
> UnwrappedLineFormatter.cpp:780:    if (!Style.isJava() && Line.First->isOneOf(tok::at, tok::minus, tok::plus))
> UnwrappedLineParser.cpp:408:            !OpeningBrace->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
> UnwrappedLineParser.cpp:430:      if (!Next->isOneOf(tok::colon, tok::arrow)) {
> UnwrappedLineParser.cpp:1160:      if (!Line.Tokens.front().Tok->isOneOf(tok::comment, tok::hash)) {
> UnwrappedLineParser.cpp:1259:          !FormatTok->isOneOf(
> UnwrappedLineParser.cpp:1325:      !Tok->isOneOf(tok::kw_register, tok::kw_struct, tok::kw_union)) {
> UnwrappedLineParser.cpp:1348:      !Token->isOneOf(tok::colon, tok::less, tok::string_literal)) {
> UnwrappedLineParser.cpp:1360:      while (!FormatTok->isOneOf(tok::semi, tok::greater) && !eof()) {
> UnwrappedLineParser.cpp:2392:        !Previous->isOneOf(tok::kw_return, tok::kw_co_await, tok::kw_co_yield,
> UnwrappedLineParser.cpp:2403:      if (!BeforeRParen || !BeforeRParen->isOneOf(tok::greater, tok::r_paren))
> UnwrappedLineParser.cpp:2452:      while (!FormatTok->isOneOf(tok::l_brace, tok::semi) && !eof())
> UnwrappedLineParser.cpp:3110:    if (!(FormatTok->isOneOf(tok::kw_catch, Keywords.kw___except,
> UnwrappedLineParser.cpp:3292:                          !FormatTok->isOneOf(tok::kw_for, tok::kw_while);
> UnwrappedLineParser.cpp:4341:  if (!IsImport && !FormatTok->isOneOf(tok::l_brace, tok::star) &&
> ```

Don't know anymore what my search was, but I'm a bit embarrassed to have missed that much...

https://github.com/llvm/llvm-project/pull/161021


More information about the cfe-commits mailing list