clang-tools 22.0.0git
clang::tidy::utils::lexer Namespace Reference

Functions

std::pair< Token, SourceLocation > getPreviousTokenAndStart (SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments)
Token getPreviousToken (SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments=true)
 Returns previous token or tok::unknown if not found.
SourceLocation findPreviousTokenStart (SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
SourceLocation findPreviousTokenKind (SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, tok::TokenKind TK)
SourceLocation findNextTerminator (SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
std::optional< Token > findNextTokenSkippingComments (SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
bool rangeContainsExpansionsOrDirectives (SourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
 Re-lex the provide Range and return false if either a macro spans multiple tokens, a pre-processor directive or failure to retrieve the next token is found, otherwise true.
std::optional< Token > getQualifyingToken (tok::TokenKind TK, CharSourceRange Range, const ASTContext &Context, const SourceManager &SM)
 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.
static bool breakAndReturnEnd (const Stmt &S)
static bool breakAndReturnEndPlus1Token (const Stmt &S)
static SourceLocation getSemicolonAfterStmtEndLoc (const SourceLocation &EndLoc, const SourceManager &SM, const LangOptions &LangOpts)
SourceLocation getUnifiedEndLoc (const Stmt &S, const SourceManager &SM, const LangOptions &LangOpts)
 Stmt->getEndLoc does not always behave the same way depending on Token type.
SourceLocation getLocationForNoexceptSpecifier (const FunctionDecl *FuncDecl, const SourceManager &SM)
 For a given FunctionDecl returns the location where you would need to place the noexcept specifier.
template<typename TokenKind, typename... TokenKinds>
SourceLocation findPreviousAnyTokenKind (SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, TokenKind TK, TokenKinds... TKs)
template<typename TokenKind, typename... TokenKinds>
SourceLocation findNextAnyTokenKind (SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, TokenKind TK, TokenKinds... TKs)
std::optional< Token > findNextTokenIncludingComments (SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)

Function Documentation

◆ breakAndReturnEnd()

bool clang::tidy::utils::lexer::breakAndReturnEnd ( const Stmt & S)
static

Definition at line 158 of file LexerUtils.cpp.

Referenced by getUnifiedEndLoc().

◆ breakAndReturnEndPlus1Token()

bool clang::tidy::utils::lexer::breakAndReturnEndPlus1Token ( const Stmt & S)
static

Definition at line 162 of file LexerUtils.cpp.

Referenced by getUnifiedEndLoc().

◆ findNextAnyTokenKind()

template<typename TokenKind, typename... TokenKinds>
SourceLocation clang::tidy::utils::lexer::findNextAnyTokenKind ( SourceLocation Start,
const SourceManager & SM,
const LangOptions & LangOpts,
TokenKind TK,
TokenKinds... TKs )

◆ findNextTerminator()

◆ findNextTokenIncludingComments()

std::optional< Token > clang::tidy::utils::lexer::findNextTokenIncludingComments ( SourceLocation Start,
const SourceManager & SM,
const LangOptions & LangOpts )
inline

◆ findNextTokenSkippingComments()

◆ findPreviousAnyTokenKind()

template<typename TokenKind, typename... TokenKinds>
SourceLocation clang::tidy::utils::lexer::findPreviousAnyTokenKind ( SourceLocation Start,
const SourceManager & SM,
const LangOptions & LangOpts,
TokenKind TK,
TokenKinds... TKs )

◆ findPreviousTokenKind()

SourceLocation clang::tidy::utils::lexer::findPreviousTokenKind ( SourceLocation Start,
const SourceManager & SM,
const LangOptions & LangOpts,
tok::TokenKind TK )

◆ findPreviousTokenStart()

SourceLocation clang::tidy::utils::lexer::findPreviousTokenStart ( SourceLocation Start,
const SourceManager & SM,
const LangOptions & LangOpts )

◆ getLocationForNoexceptSpecifier()

SourceLocation clang::tidy::utils::lexer::getLocationForNoexceptSpecifier ( const FunctionDecl * FuncDecl,
const SourceManager & SM )

For a given FunctionDecl returns the location where you would need to place the noexcept specifier.

Definition at line 222 of file LexerUtils.cpp.

References FuncDecl.

Referenced by clang::tidy::performance::NoexceptFunctionBaseCheck::check().

◆ getPreviousToken()

◆ getPreviousTokenAndStart()

std::pair< Token, SourceLocation > clang::tidy::utils::lexer::getPreviousTokenAndStart ( SourceLocation Location,
const SourceManager & SM,
const LangOptions & LangOpts,
bool SkipComments )

◆ getQualifyingToken()

std::optional< Token > clang::tidy::utils::lexer::getQualifyingToken ( tok::TokenKind TK,
CharSourceRange Range,
const ASTContext & Context,
const SourceManager & SM )

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.

Definition at line 119 of file LexerUtils.cpp.

Referenced by clang::tidy::readability::findConstToRemove(), and clang::tidy::readability::findQualToken().

◆ getSemicolonAfterStmtEndLoc()

SourceLocation clang::tidy::utils::lexer::getSemicolonAfterStmtEndLoc ( const SourceLocation & EndLoc,
const SourceManager & SM,
const LangOptions & LangOpts )
static

Definition at line 169 of file LexerUtils.cpp.

References findNextTokenSkippingComments().

Referenced by getUnifiedEndLoc().

◆ getUnifiedEndLoc()

SourceLocation clang::tidy::utils::lexer::getUnifiedEndLoc ( const Stmt & S,
const SourceManager & SM,
const LangOptions & LangOpts )

Stmt->getEndLoc does not always behave the same way depending on Token type.

See implementation for exceptions.

Definition at line 206 of file LexerUtils.cpp.

References breakAndReturnEnd(), breakAndReturnEndPlus1Token(), and getSemicolonAfterStmtEndLoc().

Referenced by clang::tidy::modernize::UseEqualsDefaultCheck::check(), and clang::tidy::utils::findEndLocation().

◆ rangeContainsExpansionsOrDirectives()

bool clang::tidy::utils::lexer::rangeContainsExpansionsOrDirectives ( SourceRange Range,
const SourceManager & SM,
const LangOptions & LangOpts )

Re-lex the provide Range and return false if either a macro spans multiple tokens, a pre-processor directive or failure to retrieve the next token is found, otherwise true.

Definition at line 95 of file LexerUtils.cpp.

Referenced by clang::tidy::modernize::UseEqualsDefaultCheck::check(), and clang::tidy::readability::declRanges().