11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/Tooling/FixIt.h"
21 auto Matcher = expr(comparisonOperatorWithCallee(functionDecl(
22 functionDecl(DurationConversionFunction())
23 .bind(
"function_decl"))))
26 Finder->addMatcher(Matcher,
this);
30 const auto *Binop = Result.Nodes.getNodeAs<BinaryOperator>(
"binop");
33 Result.Nodes.getNodeAs<FunctionDecl>(
"function_decl")->getName());
43 std::string LhsReplacement =
45 std::string RhsReplacement =
48 diag(Binop->getBeginLoc(),
"perform comparison in the duration domain")
49 << FixItHint::CreateReplacement(Binop->getSourceRange(),
50 (llvm::Twine(LhsReplacement) +
" " +
51 Binop->getOpcodeStr() +
" " +
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
std::optional< DurationScale > getScaleForDurationInverse(llvm::StringRef Name)
Given the name of an inverse Duration function (e.g., ToDoubleSeconds), return its DurationScale,...
bool isInMacro(const MatchFinder::MatchResult &Result, const Expr *E)
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 ...