clang-tools 20.0.0git
|
Classes | |
class | AbseilModule |
class | CleanupCtadCheck |
Suggests switching the initialization pattern of absl::Cleanup instances from the factory function to class template argument deduction (CTAD), in C++17 and higher. More... | |
class | DurationAdditionCheck |
Checks for cases where addition should be performed in the absl::Time domain. More... | |
class | DurationComparisonCheck |
Prefer comparison in the absl::Duration domain instead of the numeric domain. More... | |
class | DurationConversionCastCheck |
Checks for casts of absl::Duration conversion functions, and recommends the right conversion function instead. More... | |
class | DurationDivisionCheck |
class | DurationFactoryFloatCheck |
This check finds cases where Duration factories are being called with floating point arguments, but could be called using integer arguments. More... | |
class | DurationFactoryScaleCheck |
This check finds cases where the incorrect Duration factory function is being used by looking for scaling constants inside the factory argument and suggesting a more appropriate factory. More... | |
struct | DurationScale2IndexFunctor |
class | DurationSubtractionCheck |
Checks for cases where subtraction should be performed in the absl::Duration domain. More... | |
class | DurationUnnecessaryConversionCheck |
Finds and fixes cases where absl::Duration values are being converted to numeric types and back again. More... | |
class | FasterStrsplitDelimiterCheck |
Finds instances of absl::StrSplit() or absl::MaxSplits() where the delimiter is a single character string literal and replaces it with a character. More... | |
class | NoInternalDependenciesCheck |
Finds instances where the user depends on internal details and warns them against doing so. More... | |
class | NoNamespaceCheck |
This check ensures users don't open namespace absl, as that violates Abseil's compatibility guidelines. More... | |
class | RedundantStrcatCallsCheck |
Flags redundant calls to absl::StrCat when the result is being passed to another call of absl::StrCat/absl::StrAppend. More... | |
class | StrCatAppendCheck |
Flags uses of absl::StrCat to append to a string. More... | |
class | StringFindStartswithCheck |
class | StringFindStrContainsCheck |
Finds s.find(...) == string::npos comparisons (for various string-like types) and suggests replacing with absl::StrContains. More... | |
class | TimeComparisonCheck |
Prefer comparison in the absl::Time domain instead of the numeric domain. More... | |
class | TimeSubtractionCheck |
Finds and fixes absl::Time subtraction expressions to do subtraction in the time domain instead of the numeric domain. More... | |
class | UpgradeDurationConversionsCheck |
Finds deprecated uses of absl::Duration arithmetic operators and factories. More... | |
Enumerations | |
enum class | DurationScale : std::uint8_t { Hours = 0 , Minutes , Seconds , Milliseconds , Microseconds , Nanoseconds } |
Duration factory and conversion scales. More... | |
Functions | |
static ClangTidyModuleRegistry::Add< AbseilModule > | X ("abseil-module", "Add Abseil checks.") |
RewriteRuleWith< std::string > | CleanupCtadCheckImpl () |
static bool | insideMacroDefinition (const MatchFinder::MatchResult &Result, SourceRange Range) |
static std::optional< DurationScale > | getScaleForFactory (llvm::StringRef FactoryName) |
static double | getValue (const IntegerLiteral *IntLit, const FloatingLiteral *FloatLit) |
static std::optional< std::tuple< DurationScale, double > > | getNewScaleSingleStep (DurationScale OldScale, double Multiplier) |
static std::optional< DurationScale > | getNewScale (DurationScale OldScale, double Multiplier) |
static std::optional< llvm::APSInt > | truncateIfIntegral (const FloatingLiteral &FloatLiteral) |
Returns an integer if the fractional part of a FloatingLiteral is 0 . | |
const std::pair< llvm::StringRef, llvm::StringRef > & | getDurationInverseForScale (DurationScale Scale) |
Given a Scale return the fully qualified inverse functions for it. | |
static std::optional< std::string > | rewriteInverseDurationCall (const MatchFinder::MatchResult &Result, DurationScale Scale, const Expr &Node) |
If Node is a call to the inverse of Scale , return that inverse's argument, otherwise std::nullopt. | |
static std::optional< std::string > | rewriteInverseTimeCall (const MatchFinder::MatchResult &Result, DurationScale Scale, const Expr &Node) |
If Node is a call to the inverse of Scale , return that inverse's argument, otherwise std::nullopt. | |
llvm::StringRef | getDurationFactoryForScale (DurationScale Scale) |
Returns the factory function name for a given Scale . | |
llvm::StringRef | getTimeFactoryForScale (DurationScale Scale) |
Given a 'Scale', return the appropriate factory function call for constructing a Time for that scale. | |
llvm::StringRef | getTimeInverseForScale (DurationScale Scale) |
Returns the Time factory function name for a given Scale . | |
bool | isLiteralZero (const MatchFinder::MatchResult &Result, const Expr &Node) |
Returns true if Node is a value which evaluates to a literal 0 . | |
std::optional< std::string > | stripFloatCast (const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node) |
Possibly strip a floating point cast expression. | |
std::optional< std::string > | stripFloatLiteralFraction (const MatchFinder::MatchResult &Result, const Expr &Node) |
std::string | simplifyDurationFactoryArg (const MatchFinder::MatchResult &Result, const Expr &Node) |
std::optional< DurationScale > | getScaleForDurationInverse (llvm::StringRef Name) |
Given the name of an inverse Duration function (e.g., ToDoubleSeconds ), return its DurationScale , or std::nullopt if a match is not found. | |
std::optional< DurationScale > | getScaleForTimeInverse (llvm::StringRef Name) |
Given the name of an inverse Time function (e.g., ToUnixSeconds ), return its DurationScale , or std::nullopt if a match is not found. | |
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 make it a suitable Duration . | |
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 . | |
bool | isInMacro (const MatchFinder::MatchResult &Result, const Expr *E) |
bool | isLiteralZero (const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node) |
std::optional< std::string > | stripFloatLiteralFraction (const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node) |
Possibly remove the fractional part of a floating point literal. | |
std::string | simplifyDurationFactoryArg (const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node) |
Possibly further simplify a duration factory function's argument, without changing the scale of the factory function. | |
bool | isInMacro (const ast_matchers::MatchFinder::MatchResult &Result, const Expr *E) |
Return false if E is a either: not a macro at all; or an argument to one. | |
AST_MATCHER_FUNCTION (ast_matchers::internal::Matcher< FunctionDecl >, DurationConversionFunction) | |
AST_MATCHER_FUNCTION (ast_matchers::internal::Matcher< FunctionDecl >, DurationFactoryFunction) | |
AST_MATCHER_FUNCTION (ast_matchers::internal::Matcher< FunctionDecl >, TimeConversionFunction) | |
AST_MATCHER_FUNCTION_P (ast_matchers::internal::Matcher< Stmt >, comparisonOperatorWithCallee, ast_matchers::internal::Matcher< Decl >, funcDecl) | |
AST_MATCHER (Type, isCharType) | |
static transformer::RewriteRuleWith< std::string > | makeRewriteRule (ArrayRef< StringRef > StringLikeClassNames, StringRef AbseilStringsMatchHeader) |
static bool | insideMacroDefinition (const MatchFinder::MatchResult &Result, SourceRange Range) |
static bool | isConstructorAssignment (const MatchFinder::MatchResult &Result, const Expr *Node) |
static bool | isArgument (const MatchFinder::MatchResult &Result, const Expr *Node) |
static bool | isReturn (const MatchFinder::MatchResult &Result, const Expr *Node) |
static bool | parensRequired (const MatchFinder::MatchResult &Result, const Expr *Node) |
Variables | |
const auto | DefaultStringLikeClasses |
static const char | DefaultAbseilStringsMatchHeader [] = "absl/strings/match.h" |
|
strong |
Duration factory and conversion scales.
Enumerator | |
---|---|
Hours | |
Minutes | |
Seconds | |
Milliseconds | |
Microseconds | |
Nanoseconds |
Definition at line 20 of file DurationRewriter.h.
clang::tidy::abseil::AST_MATCHER | ( | Type | , |
isCharType | |||
) |
Definition at line 33 of file StringFindStrContainsCheck.cpp.
References Node.
clang::tidy::abseil::AST_MATCHER_FUNCTION | ( | ast_matchers::internal::Matcher< FunctionDecl > | , |
DurationConversionFunction | |||
) |
Definition at line 98 of file DurationRewriter.h.
clang::tidy::abseil::AST_MATCHER_FUNCTION | ( | ast_matchers::internal::Matcher< FunctionDecl > | , |
DurationFactoryFunction | |||
) |
Definition at line 110 of file DurationRewriter.h.
clang::tidy::abseil::AST_MATCHER_FUNCTION | ( | ast_matchers::internal::Matcher< FunctionDecl > | , |
TimeConversionFunction | |||
) |
Definition at line 118 of file DurationRewriter.h.
clang::tidy::abseil::AST_MATCHER_FUNCTION_P | ( | ast_matchers::internal::Matcher< Stmt > | , |
comparisonOperatorWithCallee | , | ||
ast_matchers::internal::Matcher< Decl > | , | ||
funcDecl | |||
) |
Definition at line 126 of file DurationRewriter.h.
RewriteRuleWith< std::string > clang::tidy::abseil::CleanupCtadCheckImpl | ( | ) |
Definition at line 24 of file CleanupCtadCheck.cpp.
llvm::StringRef clang::tidy::abseil::getDurationFactoryForScale | ( | DurationScale | Scale | ) |
Returns the factory function name for a given Scale
.
Given a Scale
, return the appropriate factory function call for constructing a Duration
for that scale.
Definition at line 105 of file DurationRewriter.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Nanoseconds, and Seconds.
Referenced by clang::tidy::abseil::DurationFactoryScaleCheck::check(), clang::tidy::abseil::TimeSubtractionCheck::check(), clang::tidy::abseil::TimeSubtractionCheck::registerMatchers(), and rewriteExprFromNumberToDuration().
const std::pair< llvm::StringRef, llvm::StringRef > & clang::tidy::abseil::getDurationInverseForScale | ( | DurationScale | Scale | ) |
Given a Scale
return the fully qualified inverse functions for it.
The first returned value is the inverse for double
, and the second returned value is the inverse for int64
.
Definition at line 41 of file DurationRewriter.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Nanoseconds, and Seconds.
Referenced by clang::tidy::abseil::DurationConversionCastCheck::check(), clang::tidy::abseil::TimeSubtractionCheck::check(), and rewriteInverseDurationCall().
|
static |
Definition at line 96 of file DurationFactoryScaleCheck.cpp.
References getNewScaleSingleStep().
Referenced by clang::tidy::abseil::DurationFactoryScaleCheck::check().
|
static |
Definition at line 50 of file DurationFactoryScaleCheck.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Nanoseconds, and Seconds.
Referenced by getNewScale().
std::optional< DurationScale > clang::tidy::abseil::getScaleForDurationInverse | ( | llvm::StringRef | Name | ) |
Given the name of an inverse Duration function (e.g., ToDoubleSeconds
), return its DurationScale
, or std::nullopt
if a match is not found.
Definition at line 232 of file DurationRewriter.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Name, Nanoseconds, and Seconds.
Referenced by clang::tidy::abseil::DurationComparisonCheck::check(), clang::tidy::abseil::DurationConversionCastCheck::check(), and clang::tidy::abseil::DurationSubtractionCheck::check().
|
static |
Definition at line 24 of file DurationFactoryScaleCheck.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Nanoseconds, and Seconds.
Referenced by clang::tidy::abseil::DurationFactoryScaleCheck::check().
std::optional< DurationScale > clang::tidy::abseil::getScaleForTimeInverse | ( | llvm::StringRef | Name | ) |
Given the name of an inverse Time function (e.g., ToUnixSeconds
), return its DurationScale
, or std::nullopt
if a match is not found.
Definition at line 254 of file DurationRewriter.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Name, Nanoseconds, and Seconds.
Referenced by clang::tidy::abseil::DurationAdditionCheck::check(), clang::tidy::abseil::TimeComparisonCheck::check(), clang::tidy::abseil::TimeSubtractionCheck::check(), and clang::tidy::abseil::TimeSubtractionCheck::registerMatchers().
llvm::StringRef clang::tidy::abseil::getTimeFactoryForScale | ( | DurationScale | Scale | ) |
Given a 'Scale', return the appropriate factory function call for constructing a Time
for that scale.
Definition at line 123 of file DurationRewriter.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Nanoseconds, and Seconds.
Referenced by rewriteExprFromNumberToTime().
llvm::StringRef clang::tidy::abseil::getTimeInverseForScale | ( | DurationScale | Scale | ) |
Returns the Time factory function name for a given Scale
.
Returns the Time inverse function name for a given Scale
.
Definition at line 142 of file DurationRewriter.cpp.
References Hours, Microseconds, Milliseconds, Minutes, Nanoseconds, and Seconds.
Referenced by clang::tidy::abseil::DurationAdditionCheck::check(), and rewriteInverseTimeCall().
|
static |
Definition at line 37 of file DurationFactoryScaleCheck.cpp.
Referenced by clang::tidy::abseil::DurationFactoryScaleCheck::check().
|
static |
Definition at line 22 of file DurationFactoryFloatCheck.cpp.
References Range.
Referenced by clang::tidy::abseil::DurationFactoryFloatCheck::check(), and clang::tidy::abseil::TimeSubtractionCheck::check().
|
static |
Definition at line 22 of file TimeSubtractionCheck.cpp.
References Range.
|
static |
Definition at line 47 of file TimeSubtractionCheck.cpp.
References Node.
Referenced by parensRequired().
|
static |
Definition at line 30 of file TimeSubtractionCheck.cpp.
References Node.
Referenced by parensRequired().
bool clang::tidy::abseil::isInMacro | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
const Expr * | E | ||
) |
Return false
if E
is a either: not a macro at all; or an argument to one.
In the both cases, we often want to do the transformation.
bool clang::tidy::abseil::isInMacro | ( | const MatchFinder::MatchResult & | Result, |
const Expr * | E | ||
) |
Definition at line 306 of file DurationRewriter.cpp.
Referenced by clang::tidy::abseil::DurationComparisonCheck::check(), clang::tidy::abseil::DurationConversionCastCheck::check(), clang::tidy::abseil::DurationUnnecessaryConversionCheck::check(), and clang::tidy::abseil::TimeComparisonCheck::check().
bool clang::tidy::abseil::isLiteralZero | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
const Expr & | Node | ||
) |
bool clang::tidy::abseil::isLiteralZero | ( | const MatchFinder::MatchResult & | Result, |
const Expr & | Node | ||
) |
Returns true
if Node
is a value which evaluates to a literal 0
.
Definition at line 161 of file DurationRewriter.cpp.
References Node.
Referenced by clang::tidy::abseil::DurationFactoryScaleCheck::check(), rewriteExprFromNumberToDuration(), and rewriteExprFromNumberToTime().
|
static |
Definition at line 66 of file TimeSubtractionCheck.cpp.
References Node.
Referenced by parensRequired().
|
static |
Definition at line 41 of file StringFindStrContainsCheck.cpp.
Referenced by clang::tidy::abseil::StringFindStrContainsCheck::StringFindStrContainsCheck().
|
static |
Definition at line 80 of file TimeSubtractionCheck.cpp.
References isArgument(), isConstructorAssignment(), isReturn(), and Node.
Referenced by clang::tidy::abseil::TimeSubtractionCheck::check().
std::string clang::tidy::abseil::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 make it a suitable Duration
.
Definition at line 270 of file DurationRewriter.cpp.
References getDurationFactoryForScale(), isLiteralZero(), Node, rewriteInverseDurationCall(), and simplifyDurationFactoryArg().
Referenced by clang::tidy::abseil::DurationAdditionCheck::check(), clang::tidy::abseil::DurationComparisonCheck::check(), and clang::tidy::abseil::DurationSubtractionCheck::check().
std::string clang::tidy::abseil::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
.
Definition at line 288 of file DurationRewriter.cpp.
References getTimeFactoryForScale(), isLiteralZero(), Node, and rewriteInverseTimeCall().
Referenced by clang::tidy::abseil::TimeComparisonCheck::check(), and clang::tidy::abseil::TimeSubtractionCheck::check().
|
static |
If Node
is a call to the inverse of Scale
, return that inverse's argument, otherwise std::nullopt.
Definition at line 72 of file DurationRewriter.cpp.
References getDurationInverseForScale(), and Node.
Referenced by rewriteExprFromNumberToDuration().
|
static |
If Node
is a call to the inverse of Scale
, return that inverse's argument, otherwise std::nullopt.
Definition at line 91 of file DurationRewriter.cpp.
References getTimeInverseForScale(), and Node.
Referenced by rewriteExprFromNumberToTime().
std::string clang::tidy::abseil::simplifyDurationFactoryArg | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
const Expr & | Node | ||
) |
Possibly further simplify a duration factory function's argument, without changing the scale of the factory function.
Return that simplification or the text of the argument if no simplification is possible.
std::string clang::tidy::abseil::simplifyDurationFactoryArg | ( | const MatchFinder::MatchResult & | Result, |
const Expr & | Node | ||
) |
Definition at line 217 of file DurationRewriter.cpp.
References Node, stripFloatCast(), and stripFloatLiteralFraction().
Referenced by rewriteExprFromNumberToDuration().
std::optional< std::string > clang::tidy::abseil::stripFloatCast | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
const Expr & | Node | ||
) |
Possibly strip a floating point cast expression.
If Node
represents an explicit cast to a floating point type, return the textual context of the cast argument, otherwise std::nullopt
.
Definition at line 187 of file DurationRewriter.cpp.
References Node.
Referenced by clang::tidy::abseil::DurationFactoryFloatCheck::check(), and simplifyDurationFactoryArg().
std::optional< std::string > clang::tidy::abseil::stripFloatLiteralFraction | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
const Expr & | Node | ||
) |
Possibly remove the fractional part of a floating point literal.
If Node
represents a floating point literal with a zero fractional part, return the textual context of the integral part, otherwise std::nullopt
.
std::optional< std::string > clang::tidy::abseil::stripFloatLiteralFraction | ( | const MatchFinder::MatchResult & | Result, |
const Expr & | Node | ||
) |
Definition at line 207 of file DurationRewriter.cpp.
References Node, and truncateIfIntegral().
Referenced by clang::tidy::abseil::DurationFactoryFloatCheck::check(), and simplifyDurationFactoryArg().
|
static |
Returns an integer if the fractional part of a FloatingLiteral
is 0
.
Definition at line 29 of file DurationRewriter.cpp.
Referenced by stripFloatLiteralFraction().
|
static |
|
static |
Definition at line 38 of file StringFindStrContainsCheck.cpp.
static const char clang::tidy::abseil::DefaultStringLikeClasses |
Definition at line 22 of file StringFindStartswithCheck.cpp.