blob: b1eda4861451c4227a090f2721468b17f2678191 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===--- LoopConvertCheck.h - clang-tidy-------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
11
12#include "../ClangTidyCheck.h"
13#include "../utils/IncludeInserter.h"
14#include "LoopConvertUtils.h"
15
16namespace clang {
17namespace tidy {
18namespace modernize {
19
20class LoopConvertCheck : public ClangTidyCheck {
21public:
22 LoopConvertCheck(StringRef Name, ClangTidyContext *Context);
23 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
24 return LangOpts.CPlusPlus;
25 }
26 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
27 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
28 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
29 Preprocessor *ModuleExpanderPP) override;
30 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31
32private:
33 struct RangeDescriptor {
34 RangeDescriptor();
35 bool ContainerNeedsDereference;
36 bool DerefByConstRef;
37 bool DerefByValue;
38 std::string ContainerString;
39 QualType ElemType;
40 bool NeedsReverseCall;
41 };
42
43 void getAliasRange(SourceManager &SM, SourceRange &DeclRange);
44
45 void doConversion(ASTContext *Context, const VarDecl *IndexVar,
46 const ValueDecl *MaybeContainer, const UsageResult &Usages,
47 const DeclStmt *AliasDecl, bool AliasUseRequired,
48 bool AliasFromForInit, const ForStmt *Loop,
49 RangeDescriptor Descriptor);
50
51 StringRef getContainerString(ASTContext *Context, const ForStmt *Loop,
52 const Expr *ContainerExpr);
53
54 void getArrayLoopQualifiers(ASTContext *Context,
55 const ast_matchers::BoundNodes &Nodes,
56 const Expr *ContainerExpr,
57 const UsageResult &Usages,
58 RangeDescriptor &Descriptor);
59
60 void getIteratorLoopQualifiers(ASTContext *Context,
61 const ast_matchers::BoundNodes &Nodes,
62 RangeDescriptor &Descriptor);
63
64 void determineRangeDescriptor(ASTContext *Context,
65 const ast_matchers::BoundNodes &Nodes,
66 const ForStmt *Loop, LoopFixerKind FixerKind,
67 const Expr *ContainerExpr,
68 const UsageResult &Usages,
69 RangeDescriptor &Descriptor);
70
71 bool isConvertible(ASTContext *Context, const ast_matchers::BoundNodes &Nodes,
72 const ForStmt *Loop, LoopFixerKind FixerKind);
73
74 StringRef getReverseFunction() const;
75 StringRef getReverseHeader() const;
76
77 std::unique_ptr<TUTrackingInfo> TUInfo;
78 const unsigned long long MaxCopySize;
79 const Confidence::Level MinConfidence;
80 const VariableNamer::NamingStyle NamingStyle;
81 utils::IncludeInserter Inserter;
82 bool UseReverseRanges;
83 const bool UseCxx20IfAvailable;
84 std::string ReverseFunction;
85 std::string ReverseHeader;
86};
87
88} // namespace modernize
89} // namespace tidy
90} // namespace clang
91
92#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H