| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SUSPICIOUSCALLARGUMENTCHECK_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SUSPICIOUSCALLARGUMENTCHECK_H |
| 11 |
|
| 12 |
#include "../ClangTidyCheck.h" |
| 13 |
#include "llvm/ADT/StringSet.h" |
| 14 |
#include <optional> |
| 15 |
|
| 16 |
namespace clang::tidy::readability { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class SuspiciousCallArgumentCheck : public ClangTidyCheck { |
| 25 |
enum class Heuristic { |
| 26 |
Equality, |
| 27 |
Abbreviation, |
| 28 |
Prefix, |
| 29 |
Suffix, |
| 30 |
Substring, |
| 31 |
Levenshtein, |
| 32 |
JaroWinkler, |
| 33 |
Dice |
| 34 |
}; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
enum class BoundKind { |
| 40 |
|
| 41 |
|
| 42 |
DissimilarBelow, |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
SimilarAbove |
| 48 |
}; |
| 49 |
|
| 50 |
public: |
| 51 |
static constexpr std::size_t SmallVectorSize = 8; |
| 52 |
static constexpr std::size_t HeuristicCount = |
| 53 |
static_cast<std::size_t>(Heuristic::Dice) + 1; |
| 54 |
|
| 55 |
SuspiciousCallArgumentCheck(StringRef Name, ClangTidyContext *Context); |
| 56 |
void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
| 57 |
void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 58 |
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 59 |
|
| 60 |
private: |
| 61 |
const std::size_t MinimumIdentifierNameLength; |
| 62 |
|
| 63 |
|
| 64 |
SmallVector<Heuristic, HeuristicCount> AppliedHeuristics; |
| 65 |
|
| 66 |
|
| 67 |
SmallVector<std::pair<int8_t, int8_t>, HeuristicCount> ConfiguredBounds; |
| 68 |
|
| 69 |
|
| 70 |
llvm::StringMap<std::string> AbbreviationDictionary; |
| 71 |
|
| 72 |
bool isHeuristicEnabled(Heuristic H) const; |
| 73 |
std::optional<int8_t> getBound(Heuristic H, BoundKind BK) const; |
| 74 |
|
| 75 |
|
| 76 |
SmallVector<QualType, SmallVectorSize> ArgTypes; |
| 77 |
SmallVector<StringRef, SmallVectorSize> ArgNames; |
| 78 |
SmallVector<QualType, SmallVectorSize> ParamTypes; |
| 79 |
SmallVector<StringRef, SmallVectorSize> ParamNames; |
| 80 |
|
| 81 |
void setParamNamesAndTypes(const FunctionDecl *CalleeFuncDecl); |
| 82 |
|
| 83 |
void setArgNamesAndTypes(const CallExpr *MatchedCallExpr, |
| 84 |
std::size_t InitialArgIndex); |
| 85 |
|
| 86 |
bool areParamAndArgComparable(std::size_t Position1, std::size_t Position2, |
| 87 |
const ASTContext &Ctx) const; |
| 88 |
|
| 89 |
bool areArgsSwapped(std::size_t Position1, std::size_t Position2) const; |
| 90 |
|
| 91 |
bool areNamesSimilar(StringRef Arg, StringRef Param, Heuristic H, |
| 92 |
BoundKind BK) const; |
| 93 |
}; |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
#endif |