12 #include "clang/AST/ASTContext.h" 13 #include "clang/ASTMatchers/ASTMatchFinder.h" 14 #include "clang/Tooling/FixIt.h" 22 void TimeComparisonCheck::registerMatchers(MatchFinder *Finder) {
24 expr(comparisonOperatorWithCallee(functionDecl(
25 functionDecl(TimeConversionFunction()).bind(
"function_decl"))))
28 Finder->addMatcher(Matcher,
this);
31 void TimeComparisonCheck::check(
const MatchFinder::MatchResult &Result) {
32 const auto *Binop = Result.Nodes.getNodeAs<BinaryOperator>(
"binop");
35 Result.Nodes.getNodeAs<FunctionDecl>(
"function_decl")->getName());
46 std::string LhsReplacement =
48 std::string RhsReplacement =
51 diag(Binop->getBeginLoc(),
"perform comparison in the time domain")
52 << FixItHint::CreateReplacement(Binop->getSourceRange(),
53 (llvm::Twine(LhsReplacement) +
" " +
54 Binop->getOpcodeStr() +
" " +
bool isInMacro(const MatchFinder::MatchResult &Result, const Expr *E)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< DurationScale > getScaleForTimeInverse(llvm::StringRef Name)
Given the name of an inverse Time function (e.g., ToUnixSeconds), return its DurationScale, or None if a match is not found.
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, return the expression to make it a suitable Time.