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 StringRef Name : Names)
54 Results.try_emplace((
"::std::" + Name).str(),
Replacer);
59 AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(SingleSig),
93 AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(TwoSig),
94 {
"equal",
"mismatch",
"includes",
"search"});
103 return diag(Call.getBeginLoc(),
"use an LLVM range-based algorithm");
106ArrayRef<std::pair<StringRef, StringRef>>
108 static constexpr std::pair<StringRef, StringRef> Refs[] = {
109 {
"::std::begin",
"::std::end"},
110 {
"::std::cbegin",
"::std::cend"},
111 {
"::std::rbegin",
"::std::rend"},
112 {
"::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