12#include "clang/AST/ASTContext.h"
13#include "clang/ASTMatchers/ASTMatchFinder.h"
14#include "clang/Tooling/FixIt.h"
23 expr(comparisonOperatorWithCallee(functionDecl(
24 functionDecl(TimeConversionFunction()).bind(
"function_decl"))))
27 Finder->addMatcher(Matcher,
this);
31 const auto *Binop = Result.Nodes.getNodeAs<BinaryOperator>(
"binop");
34 Result.Nodes.getNodeAs<FunctionDecl>(
"function_decl")->getName());
45 std::string LhsReplacement =
47 std::string RhsReplacement =
50 diag(Binop->getBeginLoc(),
"perform comparison in the time domain")
51 << FixItHint::CreateReplacement(Binop->getSourceRange(),
52 (llvm::Twine(LhsReplacement) +
" " +
53 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 > getScaleForTimeInverse(llvm::StringRef Name)
Given the name of an inverse Time function (e.g., ToUnixSeconds), return its DurationScale,...
std::string rewriteExprFromNumberToTime(const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale, const Expr *Node)
Assuming Node has a type int representing a time instant of Scale since The Epoch,...
bool isInMacro(const MatchFinder::MatchResult &Result, const Expr *E)