clang-tools
15.0.0git
|
#include "EasilySwappableParametersCheck.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/Support/Debug.h"
Go to the source code of this file.
Classes | |
struct | clang::tidy::bugprone::model::ConversionSequence |
The results of the steps of an Implicit Conversion Sequence is saved in an instance of this record. More... | |
struct | clang::tidy::bugprone::model::ConversionSequence::UserDefinedConvertingConstructor |
struct | clang::tidy::bugprone::model::ConversionSequence::UserDefinedConversionOperator |
struct | clang::tidy::bugprone::model::MixData |
Contains the metadata for the mixability result between two types, independently of which parameters they were calculated from. More... | |
struct | clang::tidy::bugprone::model::Mix |
A named tuple that contains the information for a mix between two concrete parameters. More... | |
struct | clang::tidy::bugprone::model::MixableParameterRange |
class | clang::tidy::bugprone::filter::relatedness_heuristic::AppearsInSameExpr |
Implements the heuristic that marks two parameters related if there is a usage for both in the same strict expression subtree. More... | |
class | clang::tidy::bugprone::filter::relatedness_heuristic::PassedToSameFunction |
Implements the heuristic that marks two parameters related if there are two separate calls to the same function (overload) and the parameters are passed to the same index in both calls, i.e f(a, b) and f(a, c) passes b and c to the same index (2) of f(), marking them related. More... | |
class | clang::tidy::bugprone::filter::relatedness_heuristic::AccessedSameMemberOf |
Implements the heuristic that marks two parameters related if the same member is accessed (referred to) inside the current function's body. More... | |
class | clang::tidy::bugprone::filter::relatedness_heuristic::Returned |
Implements the heuristic that marks two parameters related if different ReturnStmts return them from the function. More... | |
class | clang::tidy::bugprone::filter::SimilarlyUsedParameterPairSuppressor |
Helper class that is used to detect if two parameters of the same function are used in a similar fashion, to suppress the result. More... | |
Namespaces | |
clang | |
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===// | |
clang::tidy | |
clang::tidy::bugprone | |
clang::tidy::bugprone::filter | |
clang::tidy::bugprone::model | |
clang::tidy::bugprone::filter::relatedness_heuristic | |
This namespace contains the implementations for the suppression of diagnostics from similarly-used ("related") parameters. | |
Macros | |
#define | DEBUG_TYPE "EasilySwappableParametersCheck" |
Typedefs | |
using | clang::tidy::bugprone::TheCheck = EasilySwappableParametersCheck |
template<typename T , std::size_t N = SmallDataStructureSize> | |
using | clang::tidy::bugprone::filter::relatedness_heuristic::ParamToSmallSetMap = llvm::DenseMap< const ParmVarDecl *, llvm::SmallSet< T, N > > |
Functions | |
static bool | clang::tidy::bugprone::filter::isIgnoredParameter (const TheCheck &Check, const ParmVarDecl *Node) |
Returns whether the parameter's name or the parameter's type's name is configured by the user to be ignored from analysis and diagnostic. More... | |
static bool | clang::tidy::bugprone::filter::isSimilarlyUsedParameter (const SimilarlyUsedParameterPairSuppressor &Suppressor, const ParmVarDecl *Param1, const ParmVarDecl *Param2) |
static bool | clang::tidy::bugprone::filter::prefixSuffixCoverUnderThreshold (std::size_t Threshold, StringRef Str1, StringRef Str2) |
Returns whether the two strings are prefixes or suffixes of each other with at most Threshold characters differing on the non-common end. More... | |
clang::tidy::bugprone::model::LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE () | |
static bool | clang::tidy::bugprone::model::hasFlag (MixFlags Data, MixFlags SearchedFlag) |
Returns whether the SearchedFlag is turned on in the Data. More... | |
static std::string | clang::tidy::bugprone::model::formatMixFlags (MixFlags F) |
Formats the MixFlags enum into a useful, user-readable representation. More... | |
static MixData | clang::tidy::bugprone::model::isLRefEquallyBindingToType (const TheCheck &Check, const LValueReferenceType *LRef, QualType Ty, const ASTContext &Ctx, bool IsRefRHS, ImplicitConversionModellingMode ImplicitMode) |
Calculates if the reference binds an expression of the given type. More... | |
static MixData | clang::tidy::bugprone::model::approximateImplicitConversion (const TheCheck &Check, QualType LType, QualType RType, const ASTContext &Ctx, ImplicitConversionModellingMode ImplicitMode) |
Returns whether an expression of LType can be used in an RType context, as per the implicit conversion rules. More... | |
static bool | clang::tidy::bugprone::model::isUselessSugar (const Type *T) |
static NonCVRQualifiersResult | clang::tidy::bugprone::model::getNonCVRQualifiers (const ASTContext &Ctx, QualType LType, QualType RType) |
Returns if the two types are qualified in a way that ever after equating or removing local CVR qualification, even if the unqualified types would mix, the qualified ones don't, because there are some other local qualifiers that aren't equal. More... | |
static MixData | clang::tidy::bugprone::model::calculateMixability (const TheCheck &Check, QualType LType, QualType RType, const ASTContext &Ctx, ImplicitConversionModellingMode ImplicitMode) |
Approximate the way how LType and RType might refer to "essentially the
same" type, in a sense that at a particular call site, an expression of type LType and RType might be successfully passed to a variable (in our specific case, a parameter) of type RType and LType, respectively. More... | |
static bool | clang::tidy::bugprone::model::isDerivedToBase (const CXXRecordDecl *Derived, const CXXRecordDecl *Base) |
static Optional< QualType > | clang::tidy::bugprone::model::approximateStandardConversionSequence (const TheCheck &Check, QualType From, QualType To, const ASTContext &Ctx) |
static Optional< ConversionSequence > | clang::tidy::bugprone::model::tryConversionOperators (const TheCheck &Check, const CXXRecordDecl *RD, QualType ToType) |
static Optional< ConversionSequence > | clang::tidy::bugprone::model::tryConvertingConstructors (const TheCheck &Check, QualType FromType, const CXXRecordDecl *RD) |
static MixableParameterRange | clang::tidy::bugprone::model::modelMixingRange (const TheCheck &Check, const FunctionDecl *FD, std::size_t StartIndex, const filter::SimilarlyUsedParameterPairSuppressor &UsageBasedSuppressor) |
clang::tidy::bugprone::AST_MATCHER_FUNCTION (ast_matchers::internal::Matcher< Stmt >, paramRefExpr) | |
Matches DeclRefExprs and their ignorable wrappers to ParmVarDecls. More... | |
template<typename MapTy , typename ElemTy > | |
bool | clang::tidy::bugprone::filter::relatedness_heuristic::lazyMapOfSetsIntersectionExists (const MapTy &Map, const ElemTy &E1, const ElemTy &E2) |
Returns whether the sets mapped to the two elements in the map have at least one element in common. More... | |
static void | clang::tidy::bugprone::filter::padStringAtEnd (SmallVectorImpl< char > &Str, std::size_t ToLen) |
static void | clang::tidy::bugprone::filter::padStringAtBegin (SmallVectorImpl< char > &Str, std::size_t ToLen) |
static bool | clang::tidy::bugprone::filter::isCommonPrefixWithoutSomeCharacters (std::size_t N, StringRef S1, StringRef S2) |
static bool | clang::tidy::bugprone::filter::isCommonSuffixWithoutSomeCharacters (std::size_t N, StringRef S1, StringRef S2) |
clang::tidy::bugprone::AST_MATCHER_P (FunctionDecl, parameterCountGE, unsigned, N) | |
Matches functions that have at least the specified amount of parameters. More... | |
clang::tidy::bugprone::AST_MATCHER (FunctionDecl, isOverloadedUnaryOrBinaryOperator) | |
Matches any overloaded unary and binary operators. More... | |
static unsigned | clang::tidy::bugprone::clampMinimumLength (const unsigned Value) |
Returns the DefaultMinimumLength if the Value of requested minimum length is less than 2. More... | |
static SmallString< 64 > | clang::tidy::bugprone::getName (const NamedDecl *ND) |
Returns the diagnostic-friendly name of the node, or empty string. More... | |
static SmallString< 64 > | clang::tidy::bugprone::getNameOrUnnamed (const NamedDecl *ND) |
Returns the diagnostic-friendly name of the node, or a constant value. More... | |
static bool | clang::tidy::bugprone::needsToPrintTypeInDiagnostic (const model::Mix &M) |
Returns whether a particular Mix between two parameters should have the types involved diagnosed to the user. More... | |
static bool | clang::tidy::bugprone::needsToElaborateImplicitConversion (const model::Mix &M) |
Returns whether a particular Mix between the two parameters should have implicit conversions elaborated. More... | |
Variables | |
static constexpr std::size_t | DefaultMinimumLength = 2 |
The default value for the MinimumLength check option. More... | |
static constexpr llvm::StringLiteral | DefaultIgnoredParameterNames |
The default value for ignored parameter names. More... | |
static constexpr llvm::StringLiteral | DefaultIgnoredParameterTypeSuffixes |
The default value for ignored parameter type suffixes. More... | |
static constexpr bool | DefaultQualifiersMix = false |
The default value for the QualifiersMix check option. More... | |
static constexpr bool | DefaultModelImplicitConversions = true |
The default value for the ModelImplicitConversions check option. More... | |
static constexpr bool | DefaultSuppressParametersUsedTogether = true |
The default value for suppressing diagnostics about parameters that are used together. More... | |
static constexpr std::size_t | DefaultNamePrefixSuffixSilenceDissimilarityTreshold = 1 |
The default value for the NamePrefixSuffixSilenceDissimilarityTreshold check option. More... | |
static constexpr std::size_t | clang::tidy::bugprone::filter::relatedness_heuristic::SmallDataStructureSize = 4 |
#define DEBUG_TYPE "EasilySwappableParametersCheck" |
Definition at line 17 of file EasilySwappableParametersCheck.cpp.
Qualifiers CommonQualifiers |
The set of equal qualifiers between the two types.
Definition at line 594 of file EasilySwappableParametersCheck.cpp.
QualType CommonType |
Definition at line 2041 of file EasilySwappableParametersCheck.cpp.
Referenced by clang::tidy::bugprone::model::MixData::operator|().
const CXXMethodDecl* ConversionFun |
Definition at line 1096 of file EasilySwappableParametersCheck.cpp.
|
staticconstexpr |
The default value for ignored parameter names.
Definition at line 26 of file EasilySwappableParametersCheck.cpp.
|
staticconstexpr |
The default value for ignored parameter type suffixes.
Definition at line 43 of file EasilySwappableParametersCheck.cpp.
|
staticconstexpr |
The default value for the MinimumLength check option.
Definition at line 23 of file EasilySwappableParametersCheck.cpp.
Referenced by clang::tidy::bugprone::clampMinimumLength().
|
staticconstexpr |
The default value for the ModelImplicitConversions check option.
Definition at line 78 of file EasilySwappableParametersCheck.cpp.
|
staticconstexpr |
The default value for the NamePrefixSuffixSilenceDissimilarityTreshold check option.
Definition at line 87 of file EasilySwappableParametersCheck.cpp.
|
staticconstexpr |
The default value for the QualifiersMix check option.
Definition at line 75 of file EasilySwappableParametersCheck.cpp.
|
staticconstexpr |
The default value for suppressing diagnostics about parameters that are used together.
Definition at line 82 of file EasilySwappableParametersCheck.cpp.
std::string DiagnosticText |
Definition at line 1953 of file EasilySwappableParametersCheck.cpp.
MixFlags Flags |
Definition at line 1097 of file EasilySwappableParametersCheck.cpp.
Referenced by clang::tidy::bugprone::model::MixData::indicatesMixability(), clang::tidy::bugprone::model::MixData::isValid(), clang::tidy::bugprone::model::MixData::operator|(), clang::tidy::bugprone::model::MixData::operator|=(), and clang::tidy::bugprone::model::MixData::sanitize().
bool HasMixabilityBreakingQualifiers |
True if the types are qualified in a way that even after equating or removing local CVR qualification, even if the unqualified types themselves would mix, the qualified ones don't, because there are some other local qualifiers that are not equal.
Definition at line 591 of file EasilySwappableParametersCheck.cpp.
QualType LHSType |
Definition at line 2028 of file EasilySwappableParametersCheck.cpp.
QualType RHSType |
Definition at line 2028 of file EasilySwappableParametersCheck.cpp.
ConversionSequence Seq |
Definition at line 1098 of file EasilySwappableParametersCheck.cpp.
bool Trivial |
The formatted sequence is trivial if it is "Ty1 -> Ty2", but Ty1 and Ty2 are the types that are shown in the code.
A trivial diagnostic does not need to be printed.
Definition at line 1958 of file EasilySwappableParametersCheck.cpp.
Referenced by clang::tidy::bugprone::model::MixData::sanitize().