Go to the documentation of this file.
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONREWRITER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONREWRITER_H
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/ASTMatchers/ASTMatchers.h"
39 bool IsLiteralZero(
const ast_matchers::MatchFinder::MatchResult &Result,
46 llvm::Optional<std::string>
47 stripFloatCast(
const ast_matchers::MatchFinder::MatchResult &Result,
54 llvm::Optional<std::string>
76 const std::pair<llvm::StringRef, llvm::StringRef> &
85 const ast_matchers::MatchFinder::MatchResult &Result,
DurationScale Scale,
91 const ast_matchers::MatchFinder::MatchResult &Result,
DurationScale Scale,
96 bool isInMacro(
const ast_matchers::MatchFinder::MatchResult &Result,
100 DurationConversionFunction) {
103 hasAnyName(
"::absl::ToDoubleHours",
"::absl::ToDoubleMinutes",
104 "::absl::ToDoubleSeconds",
"::absl::ToDoubleMilliseconds",
105 "::absl::ToDoubleMicroseconds",
"::absl::ToDoubleNanoseconds",
106 "::absl::ToInt64Hours",
"::absl::ToInt64Minutes",
107 "::absl::ToInt64Seconds",
"::absl::ToInt64Milliseconds",
108 "::absl::ToInt64Microseconds",
"::absl::ToInt64Nanoseconds"));
112 DurationFactoryFunction) {
114 return functionDecl(hasAnyName(
"::absl::Nanoseconds",
"::absl::Microseconds",
115 "::absl::Milliseconds",
"::absl::Seconds",
116 "::absl::Minutes",
"::absl::Hours"));
120 TimeConversionFunction) {
122 return functionDecl(hasAnyName(
123 "::absl::ToUnixHours",
"::absl::ToUnixMinutes",
"::absl::ToUnixSeconds",
124 "::absl::ToUnixMillis",
"::absl::ToUnixMicros",
"::absl::ToUnixNanos"));
128 comparisonOperatorWithCallee,
129 ast_matchers::internal::Matcher<Decl>, funcDecl) {
131 return binaryOperator(
132 anyOf(hasOperatorName(
">"), hasOperatorName(
">="), hasOperatorName(
"=="),
133 hasOperatorName(
"<="), hasOperatorName(
"<")),
134 hasEitherOperand(ignoringImpCasts(callExpr(callee(funcDecl)))));
141 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONCOMPARISONCHECK_H
llvm::Optional< DurationScale > getScaleForTimeInverse(llvm::StringRef Name)
Given the name of an inverse Time function (e.g., ToUnixSeconds), return its DurationScale,...
AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher< FunctionDecl >, DurationConversionFunction)
llvm::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)
DurationScale
Duration factory and conversion scales.
const std::pair< llvm::StringRef, llvm::StringRef > & getDurationInverseForScale(DurationScale Scale)
Given a Scale return the fully qualified inverse functions for it.
static constexpr llvm::StringLiteral Name
bool IsLiteralZero(const MatchFinder::MatchResult &Result, const Expr &Node)
Returns true if Node is a value which evaluates to a literal 0.
llvm::StringRef getDurationFactoryForScale(DurationScale Scale)
Returns the factory function name for a given Scale.
std::string simplifyDurationFactoryArg(const MatchFinder::MatchResult &Result, const Expr &Node)
llvm::Optional< std::string > stripFloatCast(const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node)
Possibly strip a floating point cast expression.
AST_MATCHER_FUNCTION_P(ast_matchers::internal::Matcher< Stmt >, comparisonOperatorWithCallee, ast_matchers::internal::Matcher< Decl >, funcDecl)
llvm::StringRef getTimeFactoryForScale(DurationScale Scale)
Given a 'Scale', return the appropriate factory function call for constructing a Time for that scale.
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 ...
llvm::StringRef getTimeInverseForScale(DurationScale scale)
Returns the Time factory function name for a given Scale.
llvm::Optional< std::string > stripFloatLiteralFraction(const MatchFinder::MatchResult &Result, const Expr &Node)
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,...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//