================ @@ -0,0 +1,237 @@ +//===----------------------------------------------------------------------===// +// +// 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 "UseFromRangeContainerConstructorCheck.h" + +#include <optional> +#include <string> + +#include "../ClangTidyCheck.h" +#include "../ClangTidyDiagnosticConsumer.h" +#include "../ClangTidyOptions.h" +#include "../utils/ASTUtils.h" +#include "../utils/IncludeSorter.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/Type.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Tooling/FixIt.h" + +namespace clang::tidy::modernize { + +namespace { + +using ast_matchers::argumentCountAtLeast; +using ast_matchers::cxxConstructExpr; +using ast_matchers::cxxConstructorDecl; +using ast_matchers::cxxRecordDecl; +using ast_matchers::hasAnyName; +using ast_matchers::hasDeclaration; +using ast_matchers::ofClass; + +struct RangeObjectInfo { + const Expr *Object; + bool IsArrow; + StringRef Name; +}; + +} // namespace + +static std::optional<RangeObjectInfo> getRangeAndFunctionName(const Expr *E) { + E = E->IgnoreParenImpCasts(); + const Expr *Base = nullptr; + bool IsArrow = false; + StringRef Name; + if (const auto *MemberCall = dyn_cast<CXXMemberCallExpr>(E)) { + if (const auto *ME = dyn_cast<MemberExpr>( + MemberCall->getCallee()->IgnoreParenImpCasts())) { + Base = ME->getBase()->IgnoreParenImpCasts(); + IsArrow = ME->isArrow(); + Name = ME->getMemberDecl()->getName(); + } + } else if (const auto *Call = dyn_cast<CallExpr>(E)) { + if (Call->getNumArgs() == 1 && Call->getDirectCallee()) { + Base = Call->getArg(0)->IgnoreParenImpCasts(); + IsArrow = false; + Name = Call->getDirectCallee()->getName(); + } + } + + if (!Base) + return std::nullopt; + + // PEEL LAYER: Handle Smart Pointers (overloaded operator->) + // If the base is an operator call, we want the text of the underlying + // pointer. + if (const auto *OpCall = dyn_cast<CXXOperatorCallExpr>(Base)) { + if (OpCall->getOperator() == OO_Arrow) { + Base = OpCall->getArg(0)->IgnoreParenImpCasts(); + IsArrow = true; + } + } + + return RangeObjectInfo{Base, IsArrow, Name}; +} + +static QualType getValueType(QualType T) { + if (const auto *Spec = T->getAs<TemplateSpecializationType>()) { ---------------- zwuis wrote:
Use `getAsTemplateSpecializationType`. Ditto elsewhere. https://clang.llvm.org/docs/InternalsManual.html#the-type-class-and-its-subclasses https://github.com/llvm/llvm-project/pull/180868 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
