10#include "clang/AST/Decl.h"
11#include "llvm/ADT/ArrayRef.h"
12#include "llvm/ADT/IntrusiveRefCntPtr.h"
13#include "llvm/ADT/SmallVector.h"
14#include "llvm/ADT/StringRef.h"
15#include <initializer_list>
78 "uninitialized_default_construct",
79 "uninitialized_value_construct",
91 "set_symmetric_difference",
93 "lexicographical_compare",
105 explicit StdReplacer(SmallVector<UseRangesCheck::Signature> Signatures)
106 : Signatures(std::move(Signatures)) {}
107 std::optional<std::string>
108 getReplaceName(
const NamedDecl &OriginalName)
const override {
109 return (
"std::ranges::" + OriginalName.getName()).str();
111 ArrayRef<UseRangesCheck::Signature>
112 getReplacementSignatures()
const override {
117 SmallVector<UseRangesCheck::Signature> Signatures;
120class StdAlgorithmReplacer :
public StdReplacer {
121 using StdReplacer::StdReplacer;
122 std::optional<std::string>
123 getHeaderInclusion(
const NamedDecl & )
const override {
124 return "<algorithm>";
128class StdNumericReplacer :
public StdReplacer {
129 using StdReplacer::StdReplacer;
130 std::optional<std::string>
131 getHeaderInclusion(
const NamedDecl & )
const override {
142 static const Signature SingleRangeArgs = {{0}};
145 static const Signature TwoRangeArgs = {{0}, {2}};
148 static const Signature SinglePivotRange = {{0, 2}};
150 static const Signature SingleRangeFunc[] = {SingleRangeArgs};
152 static const Signature TwoRangeFunc[] = {TwoRangeArgs};
154 static const Signature SinglePivotFunc[] = {SinglePivotRange};
156 static const std::pair<ArrayRef<Signature>, ArrayRef<const char *>>
160 SmallString<64> Buff;
161 for (
const auto &[Signatures, Values] : AlgorithmNames) {
162 auto Replacer = llvm::makeIntrusiveRefCnt<StdAlgorithmReplacer>(
163 SmallVector<UseRangesCheck::Signature>{Signatures});
164 for (
const auto &
Name : Values) {
165 Buff.assign({
"::std::",
Name});
172 llvm::makeIntrusiveRefCnt<StdNumericReplacer>(
173 SmallVector<UseRangesCheck::Signature>{std::begin(SingleRangeFunc),
174 std::end(SingleRangeFunc)}));
180 UseReversePipe(Options.get(
"UseReversePipe", false)) {}
188 const LangOptions &LangOpts)
const {
189 return LangOpts.CPlusPlus20;
191ArrayRef<std::pair<StringRef, StringRef>>
193 static const std::pair<StringRef, StringRef> Refs[] = {
194 {
"::std::begin",
"::std::end"}, {
"::std::cbegin",
"::std::cend"}};
197std::optional<UseRangesCheck::ReverseIteratorDescriptor>
199 static const std::pair<StringRef, StringRef> Refs[] = {
200 {
"::std::rbegin",
"::std::rend"}, {
"::std::crbegin",
"::std::crend"}};
202 :
"std::ranges::reverse_view",
203 "<ranges>", Refs, UseReversePipe};
llvm::SmallString< 256U > Name
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
const LangOptions & getLangOpts() const
Returns the language options from the context.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Detects calls to standard library iterator algorithms that could be replaced with a ranges version in...
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
ArrayRef< std::pair< StringRef, StringRef > > getFreeBeginEndMethods() const override
Gets the fully qualified names of begin and end functions.
UseRangesCheck(StringRef CheckName, ClangTidyContext *Context)
void storeOptions(ClangTidyOptions::OptionMap &Options) override
Should store all options supported by this check with their current values or default values for opti...
ReplacerMap getReplacerMap() const override
Gets a map of function to replace and methods to create the replacements.
std::optional< ReverseIteratorDescriptor > getReverseDescriptor() const override
void storeOptions(ClangTidyOptions::OptionMap &Options) override
Should store all options supported by this check with their current values or default values for opti...
llvm::StringMap< llvm::IntrusiveRefCntPtr< Replacer > > ReplacerMap
SmallVector< Indexes, 2 > Signature
static constexpr const char * TwoRangeNames[]
static constexpr const char * SinglePivotRangeNames[]
static constexpr const char * SingleRangeNames[]
llvm::StringMap< ClangTidyValue > OptionMap