Author: Baranov Victor
Date: 2026-01-04T11:44:35+03:00
New Revision: 55367f2238522bff642a73730d43332d7bae30ed

URL: 
https://github.com/llvm/llvm-project/commit/55367f2238522bff642a73730d43332d7bae30ed
DIFF: 
https://github.com/llvm/llvm-project/commit/55367f2238522bff642a73730d43332d7bae30ed.diff

LOG: [clang-tidy][NFC] Simplify 'utils::lexer::findNextTokenSkippingComments' 
(#174295)

Will later refactor checks to use
`findNextTokenSkippingComments`/`findNextTokenIncludingComments` because
the 4th argument of `Lexer::findNextToken` is pain to remember every
time (moreover it has default value of skipping comments that is also
hard to remember).

The cool part is that in the 22nd release (which will happen in a few
weeks) we will be able to use `CustomQueryChecks` and I think we can
prohibit usage of `Lexer::findNextToken` in favor of "safer api"
alternatives

---------

Co-authored-by: Victor Chernyakin <[email protected]>

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
    clang-tools-extra/clang-tidy/utils/LexerUtils.h

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp 
b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
index 6e93871289ed9..3bb807c985b9a 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -75,21 +75,6 @@ SourceLocation findNextTerminator(SourceLocation Start, 
const SourceManager &SM,
   return findNextAnyTokenKind(Start, SM, LangOpts, tok::comma, tok::semi);
 }
 
-std::optional<Token>
-findNextTokenSkippingComments(SourceLocation Start, const SourceManager &SM,
-                              const LangOptions &LangOpts) {
-  while (Start.isValid()) {
-    std::optional<Token> CurrentToken =
-        Lexer::findNextToken(Start, SM, LangOpts);
-    if (!CurrentToken || !CurrentToken->is(tok::comment))
-      return CurrentToken;
-
-    Start = CurrentToken->getLocation();
-  }
-
-  return std::nullopt;
-}
-
 bool rangeContainsExpansionsOrDirectives(SourceRange Range,
                                          const SourceManager &SM,
                                          const LangOptions &LangOpts) {

diff  --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.h 
b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
index c5fb646c0efd9..e698ef68441ce 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -89,6 +89,7 @@ SourceLocation findNextAnyTokenKind(SourceLocation Start,
   }
 }
 
+// Finds next token, possibly a comment.
 inline std::optional<Token>
 findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM,
                                const LangOptions &LangOpts) {
@@ -96,9 +97,11 @@ findNextTokenIncludingComments(SourceLocation Start, const 
SourceManager &SM,
 }
 
 // Finds next token that's not a comment.
-std::optional<Token> findNextTokenSkippingComments(SourceLocation Start,
-                                                   const SourceManager &SM,
-                                                   const LangOptions 
&LangOpts);
+inline std::optional<Token>
+findNextTokenSkippingComments(SourceLocation Start, const SourceManager &SM,
+                              const LangOptions &LangOpts) {
+  return Lexer::findNextToken(Start, SM, LangOpts, false);
+}
 
 /// Re-lex the provide \p Range and return \c false if either a macro spans
 /// multiple tokens, a pre-processor directive or failure to retrieve the


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to