9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
12#include "clang/AST/ASTContext.h"
13#include "clang/Basic/TokenKinds.h"
14#include "clang/Lex/Lexer.h"
22namespace tidy::utils::lexer {
26 const LangOptions &LangOpts,
bool SkipComments =
true);
27std::pair<Token, SourceLocation>
29 const LangOptions &LangOpts,
bool SkipComments =
true);
32 const SourceManager &SM,
33 const LangOptions &LangOpts);
36 const SourceManager &SM,
37 const LangOptions &LangOpts,
41 const LangOptions &LangOpts);
43template <
typename TokenKind,
typename... TokenKinds>
45 const SourceManager &SM,
46 const LangOptions &LangOpts,
47 TokenKind TK, TokenKinds... TKs) {
48 if (Start.isInvalid() || Start.isMacroID())
52 if (L.isInvalid() || L.isMacroID())
57 if (Lexer::getRawToken(L, T, SM, LangOpts,
true))
60 if (T.isOneOf(TK, TKs...))
61 return T.getLocation();
67template <
typename TokenKind,
typename... TokenKinds>
69 const SourceManager &SM,
70 const LangOptions &LangOpts, TokenKind TK,
73 std::optional<Token> CurrentToken =
74 Lexer::findNextToken(Start, SM, LangOpts);
79 Token PotentialMatch = *CurrentToken;
80 if (PotentialMatch.isOneOf(TK, TKs...))
81 return PotentialMatch.getLocation();
86 if (PotentialMatch.is(tok::eof))
88 Start = PotentialMatch.getLastLoc();
94 const LangOptions &LangOpts);
98 const SourceManager &SM,
99 const LangOptions &LangOpts);
105 const SourceManager &SM,
106 const LangOptions &LangOpts);
114 CharSourceRange
Range,
115 const ASTContext &Context,
116 const SourceManager &SM);
121 const LangOptions &LangOpts);
126 const SourceManager &SM);
CharSourceRange Range
SourceRange for the file name.
SourceLocation getLocationForNoexceptSpecifier(const FunctionDecl *FuncDecl, const SourceManager &SM)
For a given FunctionDecl returns the location where you would need to place the noexcept specifier.
std::pair< Token, SourceLocation > getPreviousTokenAndStart(SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments)
SourceLocation getUnifiedEndLoc(const Stmt &S, const SourceManager &SM, const LangOptions &LangOpts)
Stmt->getEndLoc does not always behave the same way depending on Token type.
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,...
SourceLocation findNextTerminator(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
SourceLocation findNextAnyTokenKind(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, TokenKind TK, TokenKinds... TKs)
Token getPreviousToken(SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments)
Returns previous token or tok::unknown if not found.
std::optional< Token > findNextTokenSkippingComments(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
SourceLocation findPreviousTokenStart(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
SourceLocation findPreviousTokenKind(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, tok::TokenKind TK)
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 th...
std::optional< Token > findNextTokenIncludingComments(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
SourceLocation findPreviousAnyTokenKind(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, TokenKind TK, TokenKinds... TKs)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static constexpr const char FuncDecl[]