clang-tools  8.0.0
Classes | Enumerations | Functions
clang::tidy::abseil Namespace Reference

Classes

class  AbseilModule
 
class  DurationComparisonCheck
 Prefer comparison in the absl::Duration domain instead of the numeric domain. 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  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  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< AbseilModuleX ("abseil-module", "Add Abseil checks.")
 
static bool IsValidMacro (const MatchFinder::MatchResult &Result, const Expr *E)
 Return true if E is a either: not a macro at all; or an argument to one. More...
 
static bool InsideMacroDefinition (const MatchFinder::MatchResult &Result, SourceRange Range)
 
static llvm::Optional< DurationScalegetScaleForFactory (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< DurationScaleGetNewScale (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 > & getInverseForScale (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...
 
llvm::StringRef getFactoryForScale (DurationScale Scale)
 Returns the 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< DurationScalegetScaleForInverse (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...
 
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...
 
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...
 
 AST_MATCHER_FUNCTION (ast_matchers::internal::Matcher< FunctionDecl >, DurationConversionFunction)
 
 AST_MATCHER_FUNCTION (ast_matchers::internal::Matcher< FunctionDecl >, DurationFactoryFunction)
 

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 22 of file DurationRewriter.h.

Function Documentation

◆ AST_MATCHER_FUNCTION() [1/2]

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

Definition at line 78 of file DurationRewriter.h.

◆ AST_MATCHER_FUNCTION() [2/2]

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

Definition at line 90 of file DurationRewriter.h.

◆ getFactoryForScale()

llvm::StringRef clang::tidy::abseil::getFactoryForScale ( 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 89 of file DurationRewriter.cpp.

Referenced by clang::tidy::abseil::DurationFactoryScaleCheck::check(), and rewriteExprFromNumberToDuration().

◆ getInverseForScale()

const std::pair< llvm::StringRef, llvm::StringRef > & clang::tidy::abseil::getInverseForScale ( 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.

Referenced by rewriteInverseDurationCall().

◆ GetNewScale()

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

◆ GetNewScaleSingleStep()

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

Definition at line 57 of file DurationFactoryScaleCheck.cpp.

Referenced by GetNewScale().

◆ getScaleForFactory()

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

◆ getScaleForInverse()

llvm::Optional< DurationScale > clang::tidy::abseil::getScaleForInverse ( 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 179 of file DurationRewriter.cpp.

Referenced by clang::tidy::abseil::DurationComparisonCheck::check(), and clang::tidy::abseil::DurationSubtractionCheck::check().

◆ GetValue()

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

◆ InsideMacroDefinition()

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

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

Referenced by clang::tidy::abseil::DurationFactoryScaleCheck::check(), and rewriteExprFromNumberToDuration().

◆ IsValidMacro()

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

Return true if E is a either: not a macro at all; or an argument to one.

In the latter case, we should still transform it.

Definition at line 24 of file DurationComparisonCheck.cpp.

References Loc.

Referenced by clang::tidy::abseil::DurationComparisonCheck::check().

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

References getFactoryForScale(), IsLiteralZero(), rewriteInverseDurationCall(), and simplifyDurationFactoryArg().

Referenced by clang::tidy::abseil::DurationComparisonCheck::check(), and clang::tidy::abseil::DurationSubtractionCheck::check().

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

References getInverseForScale().

Referenced by rewriteExprFromNumberToDuration().

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

References stripFloatCast(), and stripFloatLiteralFraction().

Referenced by rewriteExprFromNumberToDuration().

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

Referenced by clang::tidy::abseil::DurationFactoryFloatCheck::check(), and simplifyDurationFactoryArg().

◆ 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 
)

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

Referenced by stripFloatLiteralFraction().

◆ X()

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