Repository: llvm/llvm-project
File: clang-tools-extra/clang-tidy/utils/LexerUtils.h (C/C++)

Code before:
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
/// next token is found, otherwise \c true.
bool rangeContainsExpansionsOrDirectives(SourceRange Range,
                                         const SourceManager &SM,
                                         const LangOptions &LangOpts);

// Represents a comment token and its source location in the original file.
struct CommentToken {
  SourceLocation Loc;
  StringRef Text;
};

/// Returns comment tokens found in the given range. If a non-comment token is
/// encountered, clears previously collected comments and continues.
std::vector<CommentToken>
getTrailingCommentsInRange(CharSourceRange Range, const SourceManager &SM,
                           const LangOptions &LangOpts);

/// Returns the first token in \p Range matching \p Pred.
/// The returned char range starts at the matched token and ends at the start
/// of the next token. Returns invalid range if no token matches.
CharSourceRange findTokenInRange(CharSourceRange Range, const SourceManager &SM,
                                 const LangOptions &LangOpts,
                                 llvm::function_ref<bool(const Token &)> Pred);

/// Assuming that ``Range`` spans a CVR-qualified type, returns the
/// token in ``Range`` that is responsible for the qualification. ``Range``
/// must be valid with respect to ``SM``.  Returns ``std::nullopt`` if no
/// qualifying tokens are found.
/// \note: doesn't support member function qualifiers.
std::optional<Token> getQualifyingToken(tok::TokenKind TK,
                                        CharSourceRange Range,
                                        const ASTContext &Context,
                                        const SourceManager &SM);

/// Stmt->getEndLoc does not always behave the same way depending on Token type.
/// See implementation for exceptions.
SourceLocation getUnifiedEndLoc(const Stmt &S, const SourceManager &SM,
                                const LangOptions &LangOpts);

/// For a given FunctionDecl returns the location where you would need to place
/// the noexcept specifier.
SourceLocation getLocationForNoexceptSpecifier(const FunctionDecl *FuncDecl,
                                               const SourceManager &SM);

Review comment (suggestion):
```suggestion
/// Returns source range of the first token in \p Range matching \p Pred.
```

Code after:
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
/// next token is found, otherwise \c true.
bool rangeContainsExpansionsOrDirectives(SourceRange Range,
                                         const SourceManager &SM,
                                         const LangOptions &LangOpts);

// Represents a comment token and its source location in the original file.
struct CommentToken {
  SourceLocation Loc;
  StringRef Text;
};

/// Returns all comment tokens found in the given range.
std::vector<CommentToken> getCommentsInRange(CharSourceRange Range,
                                             const SourceManager &SM,
                                             const LangOptions &LangOpts);

/// Returns comment tokens found in the given range. If a non-comment token is
/// encountered, clears previously collected comments and continues.
std::vector<CommentToken>
getTrailingCommentsInRange(CharSourceRange Range, const SourceManager &SM,
                           const LangOptions &LangOpts);

/// Returns source range of the first token in \p Range matching \p Pred.
/// The returned char range starts at the matched token and ends at the start
/// of the next token. Returns invalid range if no token matches.
CharSourceRange
findTokenTextInRange(CharSourceRange Range, const SourceManager &SM,
                     const LangOptions &LangOpts,
                     llvm::function_ref<bool(const Token &)> Pred);

/// Assuming that ``Range`` spans a CVR-qualified type, returns the
/// token in ``Range`` that is responsible for the qualification. ``Range``
/// must be valid with respect to ``SM``.  Returns ``std::nullopt`` if no
/// qualifying tokens are found.
/// \note: doesn't support member function qualifiers.
std::optional<Token> getQualifyingToken(tok::TokenKind TK,
                                        CharSourceRange Range,
                                        const ASTContext &Context,
                                        const SourceManager &SM);

/// Stmt->getEndLoc does not always behave the same way depending on Token type.
/// See implementation for exceptions.
SourceLocation getUnifiedEndLoc(const Stmt &S, const SourceManager &SM,