• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--- 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 
16 namespace clang {
17 namespace tidy {
18 namespace modernize {
19 
20 class LoopConvertCheck : public ClangTidyCheck {
21 public:
22   LoopConvertCheck(StringRef Name, ClangTidyContext *Context);
isLanguageVersionSupported(const LangOptions & LangOpts)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 
32 private:
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
93