11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/Lex/Lexer.h"
14 #include "clang/Tooling/FixIt.h"
25 return !clang::Lexer::makeFileCharRange(
26 clang::CharSourceRange::getCharRange(
Range),
27 *Result.SourceManager, Result.Context->getLangOpts())
31 void DurationFactoryFloatCheck::registerMatchers(MatchFinder *Finder) {
33 callExpr(callee(functionDecl(DurationFactoryFunction())),
34 hasArgument(0, anyOf(cxxStaticCastExpr(hasDestinationType(
35 realFloatingPointType())),
36 cStyleCastExpr(hasDestinationType(
37 realFloatingPointType())),
38 cxxFunctionalCastExpr(hasDestinationType(
39 realFloatingPointType())),
45 void DurationFactoryFloatCheck::check(
const MatchFinder::MatchResult &Result) {
46 const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(
"call");
52 const Expr *Arg = MatchedCall->getArg(0)->IgnoreImpCasts();
54 if (Arg->getBeginLoc().isMacroID())
57 llvm::Optional<std::string> SimpleArg =
stripFloatCast(Result, *Arg);
62 diag(MatchedCall->getBeginLoc(),
63 (llvm::Twine(
"use the integer version of absl::") +
64 MatchedCall->getDirectCallee()->getName())
66 << FixItHint::CreateReplacement(Arg->getSourceRange(), *SimpleArg);