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() +
" " +
llvm::Optional< DurationScale > getScaleForDurationInverse(llvm::StringRef Name)
Given the name of an inverse Duration function (e.g., ToDoubleSeconds), return its DurationScale...
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 ...
bool isInMacro(const MatchFinder::MatchResult &Result, const Expr *E)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result