12 #include "clang/AST/ASTContext.h" 13 #include "clang/ASTMatchers/ASTMatchFinder.h" 14 #include "clang/Tooling/FixIt.h" 22 void DurationSubtractionCheck::registerMatchers(MatchFinder *Finder) {
26 hasLHS(callExpr(callee(functionDecl(DurationConversionFunction())
27 .bind(
"function_decl")),
28 hasArgument(0, expr().bind(
"lhs_arg")))))
33 void DurationSubtractionCheck::check(
const MatchFinder::MatchResult &
Result) {
34 const auto *Binop = Result.Nodes.getNodeAs<BinaryOperator>(
"binop");
35 const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"function_decl");
38 if (Binop->getExprLoc().isMacroID() || Binop->getExprLoc().isInvalid())
45 std::string RhsReplacement =
48 const Expr *LhsArg = Result.Nodes.getNodeAs<Expr>(
"lhs_arg");
50 diag(Binop->getBeginLoc(),
"perform subtraction in the duration domain")
51 << FixItHint::CreateReplacement(
52 Binop->getSourceRange(),
53 (llvm::Twine(
"absl::") + FuncDecl->getName() +
"(" +
54 tooling::fixit::getText(*LhsArg, *Result.Context) +
" - " +
std::string rewriteExprFromNumberToDuration(const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale, const Expr *Node)
Assuming Node has type double or int representing a time interval of Scale, return the expression to ...
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
llvm::Optional< DurationScale > getScaleForInverse(llvm::StringRef Name)
Given the name of an inverse Duration function (e.g., ToDoubleSeconds), return its DurationScale...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//