================
@@ -0,0 +1,248 @@
+//===--- UseRangesCheck.cpp - clang-tidy 
----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "UseRangesCheck.h"
+#include "Matchers.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallBitVector.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cassert>
+#include <limits>
+#include <optional>
+#include <string>
+
+using namespace clang::ast_matchers;
+
+static constexpr const char BoundCall[] = "CallExpr";
+static constexpr const char FuncDecl[] = "FuncDecl";
+static constexpr const char ArgName[] = "ArgName";
+
+namespace clang::tidy::utils {
+
+static bool operator==(const UseRangesCheck::Indexes &L,
+                       const UseRangesCheck::Indexes &R) {
+  return std::tie(L.BeginArg, L.EndArg, L.ReplaceArg) ==
+         std::tie(R.BeginArg, R.EndArg, R.ReplaceArg);
+}
+
+static std::string getFullPrefix(ArrayRef<UseRangesCheck::Indexes> Signature) {
+  std::string Output;
+  llvm::raw_string_ostream OS(Output);
+  for (const UseRangesCheck::Indexes &Item : Signature) {
+    OS << Item.BeginArg << ":" << Item.EndArg << ":"
+       << (Item.ReplaceArg == Item.First ? '0' : '1');
+  }
+  return Output;
+}
+
+static llvm::hash_code hash_value(const UseRangesCheck::Indexes &Indexes) {
+  return llvm::hash_combine(Indexes.BeginArg, Indexes.EndArg,
+                            Indexes.ReplaceArg);
+}
+
+static llvm::hash_code hash_value(const UseRangesCheck::Signature &Sig) {
+  return llvm::hash_combine_range(Sig.begin(), Sig.end());
+}
+
+namespace {
+
+AST_MATCHER(Expr, hasSideEffects) {
+  return Node.HasSideEffects(Finder->getASTContext());
+}
+} // namespace
+
+static auto makeMatcher(bool IsBegin, StringRef Prefix) {
+  auto Member =
+      IsBegin ? expr(unless(hasSideEffects())).bind((ArgName + Prefix).str())
+              : expr(matchers::isStatementIdenticalToBoundNode(
+                    (ArgName + Prefix).str()));
+  return expr(
+      anyOf(cxxMemberCallExpr(
+                callee(cxxMethodDecl(IsBegin ? hasAnyName("begin", "cbegin")
+                                             : hasAnyName("end", "cend"))),
+                on(Member)),
+            callExpr(argumentCountIs(1), hasArgument(0, Member),
+                     hasDeclaration(functionDecl(
+                         IsBegin ? hasAnyName("::std::begin", "::std::cbegin")
+                                 : hasAnyName("::std::end", 
"::std::cend"))))));
+}
+static ast_matchers::internal::Matcher<CallExpr>
+makeMatcherPair(StringRef State, const UseRangesCheck::Indexes &Indexes) {
+  auto ArgPostfix = std::to_string(Indexes.BeginArg);
+  SmallString<64> ID = {BoundCall, State};
+  return callExpr(argumentCountAtLeast(
+                      std::max(Indexes.BeginArg, Indexes.EndArg) + 1),
----------------
njames93 wrote:

Again to support any weird libraries downstream users may have.

https://github.com/llvm/llvm-project/pull/97764
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to