11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/Lex/Lexer.h"
14#include "clang/Tooling/FixIt.h"
24 return !clang::Lexer::makeFileCharRange(
25 clang::CharSourceRange::getCharRange(
Range),
26 *Result.SourceManager, Result.Context->getLangOpts())
32 callExpr(callee(functionDecl(DurationFactoryFunction())),
33 hasArgument(0, anyOf(cxxStaticCastExpr(hasDestinationType(
34 realFloatingPointType())),
35 cStyleCastExpr(hasDestinationType(
36 realFloatingPointType())),
37 cxxFunctionalCastExpr(hasDestinationType(
38 realFloatingPointType())),
45 const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(
"call");
51 const Expr *Arg = MatchedCall->getArg(0)->IgnoreImpCasts();
53 if (Arg->getBeginLoc().isMacroID())
56 std::optional<std::string> SimpleArg =
stripFloatCast(Result, *Arg);
61 diag(MatchedCall->getBeginLoc(),
"use the integer version of absl::%0")
62 << MatchedCall->getDirectCallee()->getName()
63 << FixItHint::CreateReplacement(Arg->getSourceRange(), *SimpleArg);
CharSourceRange Range
SourceRange for the file name.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
std::optional< std::string > stripFloatCast(const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node)
Possibly strip a floating point cast expression.
std::optional< std::string > stripFloatLiteralFraction(const MatchFinder::MatchResult &Result, const Expr &Node)
static bool insideMacroDefinition(const MatchFinder::MatchResult &Result, SourceRange Range)