clang-tools 10.0.0

Classes | Enumerations | Functions
clang::tidy::abseil Namespace Reference

## Classes
class | AbseilModule
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 | 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 | DurationScale : std::uint8_t { DurationScale::Hours = 0, DurationScale::Minutes, DurationScale::Seconds, DurationScale::Milliseconds, DurationScale::Microseconds, DurationScale::Nanoseconds }
| Duration factory and conversion scales. More...

## Functions
static ClangTidyModuleRegistry::Add< AbseilModule > | X ("abseil-module", "Add Abseil checks.")
static bool | InsideMacroDefinition (const MatchFinder::MatchResult &Result, SourceRange Range)
static llvm::Optional< DurationScale > | getScaleForFactory (llvm::StringRef FactoryName)
static double | GetValue (const IntegerLiteral *IntLit, const FloatingLiteral *FloatLit)
static llvm::Optional< std::tuple< DurationScale, double > > | GetNewScaleSingleStep (DurationScale OldScale, double Multiplier)
static llvm::Optional< DurationScale > | GetNewScale (DurationScale OldScale, double Multiplier)
static llvm::Optional< llvm::APSInt > | truncateIfIntegral (const FloatingLiteral &FloatLiteral)
| Returns an integer if the fractional part of a `FloatingLiteral` is `0`. More...
const std::pair< llvm::StringRef, llvm::StringRef > & | getDurationInverseForScale (DurationScale Scale)
| Given a `Scale` return the fully qualified inverse functions for it. More...
static llvm::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 None. More...
static llvm::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 None. More...
llvm::StringRef | getDurationFactoryForScale (DurationScale Scale)
| Returns the factory function name for a given `Scale`. More...
llvm::StringRef | getTimeFactoryForScale (DurationScale scale)
| Given a 'Scale', return the appropriate factory function call for constructing a `Time` for that scale. More...
llvm::StringRef | getTimeInverseForScale (DurationScale scale)
| Returns the Time factory function name for a given `Scale`. More...
bool | IsLiteralZero (const MatchFinder::MatchResult &Result, const Expr &Node)
| Returns `true` if `Node` is a value which evaluates to a literal `0`. More...
llvm::Optional< std::string > | stripFloatCast (const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node)
| Possibly strip a floating point cast expression. More...
llvm::Optional< std::string > | stripFloatLiteralFraction (const MatchFinder::MatchResult &Result, const Expr &Node)
std::string | simplifyDurationFactoryArg (const MatchFinder::MatchResult &Result, const Expr &Node)
llvm::Optional< DurationScale > | getScaleForDurationInverse (llvm::StringRef Name)
| Given the name of an inverse Duration function (e.g., `ToDoubleSeconds`), return its `DurationScale`, or `None` if a match is not found. More...
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. More...
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`. More...
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`. More...
bool | isInMacro (const MatchFinder::MatchResult &Result, const Expr *E)
bool | IsLiteralZero (const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node)
llvm::Optional< std::string > | stripFloatLiteralFraction (const ast_matchers::MatchFinder::MatchResult &Result, const Expr &Node)
| Possibly remove the fractional part of a floating point literal. More...
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. More...
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. More...
| 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)
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)

## Enumeration Type Documentation

## ◆ DurationScale

enum clang::tidy::abseil::DurationScale : std::uint8_t
| strong

Duration factory and conversion scales.

Enumerator
Hours |
Minutes |
Seconds |
Milliseconds |
Microseconds |
Nanoseconds |

Definition at line 21 of file DurationRewriter.h.

## Function Documentation

## ◆ AST_MATCHER_FUNCTION() [1/3]

clang::tidy::abseil::AST_MATCHER_FUNCTION | ( | ast_matchers::internal::Matcher< FunctionDecl > | ,
|  | DurationConversionFunction |
| ) |  |

Definition at line 99 of file DurationRewriter.h.

## ◆ AST_MATCHER_FUNCTION() [2/3]

clang::tidy::abseil::AST_MATCHER_FUNCTION | ( | ast_matchers::internal::Matcher< FunctionDecl > | ,
|  | DurationFactoryFunction |
| ) |  |

Definition at line 111 of file DurationRewriter.h.

## ◆ AST_MATCHER_FUNCTION() [3/3]

clang::tidy::abseil::AST_MATCHER_FUNCTION | ( | ast_matchers::internal::Matcher< FunctionDecl > | ,
|  | TimeConversionFunction |
| ) |  |

Definition at line 119 of file DurationRewriter.h.

## ◆ AST_MATCHER_FUNCTION_P()

clang::tidy::abseil::AST_MATCHER_FUNCTION_P | ( | ast_matchers::internal::Matcher< Stmt > | ,
|  | comparisonOperatorWithCallee | ,
|  | ast_matchers::internal::Matcher< Decl > | ,
|  | funcDecl |
| ) |  |

Definition at line 127 of file DurationRewriter.h.

## ◆ getDurationFactoryForScale()

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 104 of file DurationRewriter.cpp.

## ◆ getDurationInverseForScale()

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 40 of file DurationRewriter.cpp.

## ◆ GetNewScale()

static llvm::Optional<DurationScale> clang::tidy::abseil::GetNewScale | ( | DurationScale | OldScale,
|  | double | Multiplier
| ) |  |
| static

Definition at line 102 of file DurationFactoryScaleCheck.cpp.

References GetNewScaleSingleStep().

## ◆ GetNewScaleSingleStep()

static llvm::Optional<std::tuple<DurationScale, double> > clang::tidy::abseil::GetNewScaleSingleStep | ( | DurationScale | OldScale,
|  | double | Multiplier
| ) |  |
| static

Definition at line 56 of file DurationFactoryScaleCheck.cpp.

Referenced by GetNewScale().

## ◆ getScaleForDurationInverse()

llvm::Optional< DurationScale > clang::tidy::abseil::getScaleForDurationInverse | ( | llvm::StringRef | Name | ) |

Given the name of an inverse Duration function (e.g., `ToDoubleSeconds`), return its `DurationScale`, or `None` if a match is not found.

Definition at line 231 of file DurationRewriter.cpp.

## ◆ getScaleForFactory()

static llvm::Optional<DurationScale> clang::tidy::abseil::getScaleForFactory | ( | llvm::StringRef | FactoryName | ) |
| static

Definition at line 25 of file DurationFactoryScaleCheck.cpp.

## ◆ getScaleForTimeInverse()

llvm::Optional< DurationScale > clang::tidy::abseil::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.

Definition at line 253 of file DurationRewriter.cpp.

## ◆ getTimeFactoryForScale()

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 122 of file DurationRewriter.cpp.

## ◆ getTimeInverseForScale()

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 141 of file DurationRewriter.cpp.

## ◆ GetValue()

static double clang::tidy::abseil::GetValue | ( | const IntegerLiteral * | IntLit,
|  | const FloatingLiteral * | FloatLit
| ) |  |
| static

Definition at line 43 of file DurationFactoryScaleCheck.cpp.

## ◆ InsideMacroDefinition() [1/2]

static bool clang::tidy::abseil::InsideMacroDefinition | ( | const MatchFinder::MatchResult & | Result,
|  | SourceRange | Range
| ) |  |
| static

Definition at line 22 of file DurationFactoryFloatCheck.cpp.

## ◆ InsideMacroDefinition() [2/2]

static bool clang::tidy::abseil::InsideMacroDefinition | ( | const MatchFinder::MatchResult & | Result,
|  | SourceRange | Range
| ) |  |
| static

Definition at line 22 of file TimeSubtractionCheck.cpp.

## ◆ isArgument()

static bool clang::tidy::abseil::isArgument | ( | const MatchFinder::MatchResult & | Result,
|  | const Expr * | Node
| ) |  |
| static

Definition at line 47 of file TimeSubtractionCheck.cpp.

## ◆ isConstructorAssignment()

static bool clang::tidy::abseil::isConstructorAssignment | ( | const MatchFinder::MatchResult & | Result,
|  | const Expr * | Node
| ) |  |
| static

Definition at line 30 of file TimeSubtractionCheck.cpp.

## ◆ isInMacro() [1/2]

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.

## ◆ isInMacro() [2/2]

bool clang::tidy::abseil::isInMacro | ( | const MatchFinder::MatchResult & | Result,
|  | const Expr * | E
| ) |  |

Definition at line 305 of file DurationRewriter.cpp.

## ◆ IsLiteralZero() [1/2]

bool clang::tidy::abseil::IsLiteralZero | ( | const ast_matchers::MatchFinder::MatchResult & | Result,
|  | const Expr & | Node
| ) |  |

## ◆ IsLiteralZero() [2/2]

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 160 of file DurationRewriter.cpp.

## ◆ isReturn()

static bool clang::tidy::abseil::isReturn | ( | const MatchFinder::MatchResult & | Result,
|  | const Expr * | Node
| ) |  |
| static

Definition at line 66 of file TimeSubtractionCheck.cpp.

## ◆ parensRequired()

static bool clang::tidy::abseil::parensRequired | ( | const MatchFinder::MatchResult & | Result,
|  | const Expr * | Node
| ) |  |
| static

Definition at line 80 of file TimeSubtractionCheck.cpp.

## ◆ rewriteExprFromNumberToDuration()

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 269 of file DurationRewriter.cpp.

## ◆ rewriteExprFromNumberToTime()

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 287 of file DurationRewriter.cpp.

## ◆ rewriteInverseDurationCall()

static llvm::Optional<std::string> clang::tidy::abseil::rewriteInverseDurationCall | ( | const MatchFinder::MatchResult & | Result,
|  | DurationScale | Scale,
|  | const Expr & | Node
| ) |  |
| static

If `Node` is a call to the inverse of `Scale`, return that inverse's argument, otherwise None.

Definition at line 71 of file DurationRewriter.cpp.

## ◆ rewriteInverseTimeCall()

static llvm::Optional<std::string> clang::tidy::abseil::rewriteInverseTimeCall | ( | const MatchFinder::MatchResult & | Result,
|  | DurationScale | Scale,
|  | const Expr & | Node
| ) |  |
| static

If `Node` is a call to the inverse of `Scale`, return that inverse's argument, otherwise None.

Definition at line 90 of file DurationRewriter.cpp.

## ◆ simplifyDurationFactoryArg() [1/2]

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.

## ◆ simplifyDurationFactoryArg() [2/2]

std::string clang::tidy::abseil::simplifyDurationFactoryArg | ( | const MatchFinder::MatchResult & | Result,
|  | const Expr & | Node
| ) |  |

Definition at line 216 of file DurationRewriter.cpp.

## ◆ stripFloatCast()

llvm::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 `None`.

Definition at line 186 of file DurationRewriter.cpp.

## ◆ stripFloatLiteralFraction() [1/2]

llvm::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 `None`.

## ◆ stripFloatLiteralFraction() [2/2]

llvm::Optional<std::string> clang::tidy::abseil::stripFloatLiteralFraction | ( | const MatchFinder::MatchResult & | Result,
|  | const Expr & | Node
| ) |  |

Definition at line 206 of file DurationRewriter.cpp.

## ◆ truncateIfIntegral()

static llvm::Optional<llvm::APSInt> clang::tidy::abseil::truncateIfIntegral | ( | const FloatingLiteral & | FloatLiteral | ) |
| static

Returns an integer if the fractional part of a `FloatingLiteral` is `0`.

Definition at line 28 of file DurationRewriter.cpp.

## ◆ X()

static ClangTidyModuleRegistry::Add<AbseilModule> clang::tidy::abseil::X | ( | "abseil-module" | ,
|  | "Add Abseil checks." |
| ) |  |
| static

Referenced by clang::tidy::abseil::AbseilModule::addCheckFactories(), and main().