12 #include "clang/AST/ASTContext.h" 13 #include "clang/ASTMatchers/ASTMatchFinder.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);
static bool InsideMacroDefinition(const MatchFinder::MatchResult &Result, SourceRange Range)
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
llvm::Optional< std::string > stripFloatCast(const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node)
Possibly strip a floating point cast expression.
llvm::Optional< std::string > stripFloatLiteralFraction(const MatchFinder::MatchResult &Result, const Expr &Node)