File indexing completed on 2026-05-10 08:36:20
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
0011
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/IncludeInserter.h"
0014 #include "LoopConvertUtils.h"
0015
0016 namespace clang::tidy::modernize {
0017
0018 class LoopConvertCheck : public ClangTidyCheck {
0019 public:
0020 LoopConvertCheck(StringRef Name, ClangTidyContext *Context);
0021 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0022 return LangOpts.CPlusPlus;
0023 }
0024 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0025 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0026 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0027 Preprocessor *ModuleExpanderPP) override;
0028 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0029
0030 private:
0031 struct RangeDescriptor {
0032 RangeDescriptor() = default;
0033 bool ContainerNeedsDereference = false;
0034 bool DerefByConstRef = false;
0035 bool DerefByValue = false;
0036 std::string ContainerString;
0037 QualType ElemType;
0038 bool NeedsReverseCall = false;
0039 };
0040
0041 void getAliasRange(SourceManager &SM, SourceRange &DeclRange);
0042
0043 void doConversion(ASTContext *Context, const VarDecl *IndexVar,
0044 const ValueDecl *MaybeContainer, const UsageResult &Usages,
0045 const DeclStmt *AliasDecl, bool AliasUseRequired,
0046 bool AliasFromForInit, const ForStmt *Loop,
0047 RangeDescriptor Descriptor);
0048
0049 StringRef getContainerString(ASTContext *Context, const ForStmt *Loop,
0050 const Expr *ContainerExpr);
0051
0052 void getArrayLoopQualifiers(ASTContext *Context,
0053 const ast_matchers::BoundNodes &Nodes,
0054 const Expr *ContainerExpr,
0055 const UsageResult &Usages,
0056 RangeDescriptor &Descriptor);
0057
0058 void getIteratorLoopQualifiers(ASTContext *Context,
0059 const ast_matchers::BoundNodes &Nodes,
0060 RangeDescriptor &Descriptor);
0061
0062 void determineRangeDescriptor(ASTContext *Context,
0063 const ast_matchers::BoundNodes &Nodes,
0064 const ForStmt *Loop, LoopFixerKind FixerKind,
0065 const Expr *ContainerExpr,
0066 const UsageResult &Usages,
0067 RangeDescriptor &Descriptor);
0068
0069 bool isConvertible(ASTContext *Context, const ast_matchers::BoundNodes &Nodes,
0070 const ForStmt *Loop, LoopFixerKind FixerKind);
0071
0072 StringRef getReverseFunction() const;
0073 StringRef getReverseHeader() const;
0074
0075 std::unique_ptr<TUTrackingInfo> TUInfo;
0076 const unsigned long long MaxCopySize;
0077 const Confidence::Level MinConfidence;
0078 const VariableNamer::NamingStyle NamingStyle;
0079 utils::IncludeInserter Inserter;
0080 bool UseReverseRanges;
0081 const bool UseCxx20IfAvailable;
0082 std::string ReverseFunction;
0083 std::string ReverseHeader;
0084 };
0085
0086 }
0087
0088 #endif