17class StdToLLVMReplacer :
public utils::UseRangesCheck::Replacer {
19 explicit StdToLLVMReplacer(
20 ArrayRef<utils::UseRangesCheck::Signature> Signatures)
21 : Signatures(Signatures) {}
23 ArrayRef<utils::UseRangesCheck::Signature>
24 getReplacementSignatures()
const override {
28 std::optional<std::string>
29 getReplaceName(
const NamedDecl &OriginalName)
const override {
30 return (
"llvm::" + OriginalName.getName()).str();
33 std::optional<std::string>
34 getHeaderInclusion(
const NamedDecl &)
const override {
35 return "llvm/ADT/STLExtras.h";
39 ArrayRef<utils::UseRangesCheck::Signature> Signatures;
48 static const Signature TwoSig = {{0}, {2}};
50 const auto AddStdToLLVM =
51 [&Results](llvm::IntrusiveRefCntPtr<Replacer>
Replacer,
52 std::initializer_list<StringRef> Names) {
53 for (
const auto &Name : Names) {
54 Results.try_emplace((
"::std::" + Name).str(),
Replacer);
59 AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(SingleSig),
61 "none_of",
"for_each",
63 "find_if_not",
"fill",
66 "transform",
"replace",
67 "remove_if",
"stable_sort",
68 "partition",
"partition_point",
69 "is_sorted",
"min_element",
70 "max_element",
"binary_search",
71 "lower_bound",
"upper_bound",
72 "unique",
"uninitialized_copy"});
75 AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(TwoSig),
76 {
"equal",
"mismatch",
"includes"});
85 return diag(Call.getBeginLoc(),
"use an LLVM range-based algorithm");
88ArrayRef<std::pair<StringRef, StringRef>>
90 static constexpr std::pair<StringRef, StringRef> Refs[] = {
91 {
"::std::begin",
"::std::end"},
92 {
"::std::cbegin",
"::std::cend"},
93 {
"::std::rbegin",
"::std::rend"},
94 {
"::std::crbegin",
"::std::crend"},
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
UseRangesCheck(StringRef Name, ClangTidyContext *Context)
ReplacerMap getReplacerMap() const override
Gets a map of function to replace and methods to create the replacements.
DiagnosticBuilder createDiag(const CallExpr &Call) override
Create a diagnostic for the CallExpr Override this to support custom diagnostic messages.
ArrayRef< std::pair< StringRef, StringRef > > getFreeBeginEndMethods() const override
Gets the fully qualified names of begin and end functions.
llvm::StringMap< llvm::IntrusiveRefCntPtr< Replacer > > ReplacerMap
SmallVector< Indexes, 2 > Signature