11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/Tooling/FixIt.h"
21 void DurationComparisonCheck::registerMatchers(MatchFinder *Finder) {
22 auto Matcher = expr(comparisonOperatorWithCallee(functionDecl(
23 functionDecl(DurationConversionFunction())
24 .bind(
"function_decl"))))
27 Finder->addMatcher(Matcher,
this);
30 void DurationComparisonCheck::check(
const MatchFinder::MatchResult &Result) {
31 const auto *Binop = Result.Nodes.getNodeAs<BinaryOperator>(
"binop");
34 Result.Nodes.getNodeAs<FunctionDecl>(
"function_decl")->getName());
44 std::string LhsReplacement =
46 std::string RhsReplacement =
49 diag(Binop->getBeginLoc(),
"perform comparison in the duration domain")
50 << FixItHint::CreateReplacement(Binop->getSourceRange(),
51 (llvm::Twine(LhsReplacement) +
" " +
52 Binop->getOpcodeStr() +
" " +