1 //===--- LoopConvertCheck.h - clang-tidy-------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
12 #include "../ClangTidyCheck.h"
13 #include "../utils/IncludeInserter.h"
14 #include "LoopConvertUtils.h"
16 namespace clang::tidy::modernize
{
18 class LoopConvertCheck
: public ClangTidyCheck
{
20 LoopConvertCheck(StringRef Name
, ClangTidyContext
*Context
);
21 bool isLanguageVersionSupported(const LangOptions
&LangOpts
) const override
{
22 return LangOpts
.CPlusPlus
;
24 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
25 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
26 void registerPPCallbacks(const SourceManager
&SM
, Preprocessor
*PP
,
27 Preprocessor
*ModuleExpanderPP
) override
;
28 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
31 struct RangeDescriptor
{
32 RangeDescriptor() = default;
33 bool ContainerNeedsDereference
= false;
34 bool DerefByConstRef
= false;
35 bool DerefByValue
= false;
36 std::string ContainerString
;
38 bool NeedsReverseCall
= false;
41 void getAliasRange(SourceManager
&SM
, SourceRange
&DeclRange
);
43 void doConversion(ASTContext
*Context
, const VarDecl
*IndexVar
,
44 const ValueDecl
*MaybeContainer
, const UsageResult
&Usages
,
45 const DeclStmt
*AliasDecl
, bool AliasUseRequired
,
46 bool AliasFromForInit
, const ForStmt
*Loop
,
47 RangeDescriptor Descriptor
);
49 StringRef
getContainerString(ASTContext
*Context
, const ForStmt
*Loop
,
50 const Expr
*ContainerExpr
);
52 void getArrayLoopQualifiers(ASTContext
*Context
,
53 const ast_matchers::BoundNodes
&Nodes
,
54 const Expr
*ContainerExpr
,
55 const UsageResult
&Usages
,
56 RangeDescriptor
&Descriptor
);
58 void getIteratorLoopQualifiers(ASTContext
*Context
,
59 const ast_matchers::BoundNodes
&Nodes
,
60 RangeDescriptor
&Descriptor
);
62 void determineRangeDescriptor(ASTContext
*Context
,
63 const ast_matchers::BoundNodes
&Nodes
,
64 const ForStmt
*Loop
, LoopFixerKind FixerKind
,
65 const Expr
*ContainerExpr
,
66 const UsageResult
&Usages
,
67 RangeDescriptor
&Descriptor
);
69 bool isConvertible(ASTContext
*Context
, const ast_matchers::BoundNodes
&Nodes
,
70 const ForStmt
*Loop
, LoopFixerKind FixerKind
);
72 StringRef
getReverseFunction() const;
73 StringRef
getReverseHeader() const;
75 std::unique_ptr
<TUTrackingInfo
> TUInfo
;
76 const unsigned long long MaxCopySize
;
77 const Confidence::Level MinConfidence
;
78 const VariableNamer::NamingStyle NamingStyle
;
79 utils::IncludeInserter Inserter
;
80 bool UseReverseRanges
;
81 const bool UseCxx20IfAvailable
;
82 std::string ReverseFunction
;
83 std::string ReverseHeader
;
86 } // namespace clang::tidy::modernize
88 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H