11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Tooling/FixIt.h" 24 return !clang::Lexer::makeFileCharRange(
25 clang::CharSourceRange::getCharRange(Range),
26 *Result.SourceManager, Result.Context->getLangOpts())
30 void DurationFactoryFloatCheck::registerMatchers(MatchFinder *Finder) {
32 callExpr(callee(functionDecl(DurationFactoryFunction())),
33 hasArgument(0, anyOf(cxxStaticCastExpr(hasDestinationType(
34 realFloatingPointType())),
35 cStyleCastExpr(hasDestinationType(
36 realFloatingPointType())),
37 cxxFunctionalCastExpr(hasDestinationType(
38 realFloatingPointType())),
44 void DurationFactoryFloatCheck::check(
const MatchFinder::MatchResult &
Result) {
45 const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(
"call");
51 const Expr *Arg = MatchedCall->getArg(0)->IgnoreImpCasts();
53 if (Arg->getBeginLoc().isMacroID())
56 llvm::Optional<std::string> SimpleArg =
stripFloatCast(Result, *Arg);
61 diag(MatchedCall->getBeginLoc(),
62 (llvm::Twine(
"use the integer version of absl::") +
63 MatchedCall->getDirectCallee()->getName())
65 << FixItHint::CreateReplacement(Arg->getSourceRange(), *SimpleArg);
static bool InsideMacroDefinition(const MatchFinder::MatchResult &Result, SourceRange Range)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
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)