clang-tools  14.0.0git
LoopConvertCheck.h
Go to the documentation of this file.
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 
21 public:
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 
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
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::modernize::UsageResult
llvm::SmallVector< Usage, 8 > UsageResult
Definition: LoopConvertUtils.h:275
clang::tidy::utils::IncludeInserter
Produces fixes to insert specified includes to source files, if not yet present.
Definition: IncludeInserter.h:55
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::modernize::LoopConvertCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: LoopConvertCheck.cpp:838
clang::tidy::modernize::LoopConvertCheck
Definition: LoopConvertCheck.h:20
LoopConvertUtils.h
clang::tidy::modernize::LoopConvertCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: LoopConvertCheck.cpp:484
clang::tidy::modernize::LoopFixerKind
LoopFixerKind
Definition: LoopConvertUtils.h:29
clang::tidy::modernize::LoopConvertCheck::LoopConvertCheck
LoopConvertCheck(StringRef Name, ClangTidyContext *Context)
Definition: LoopConvertCheck.cpp:460
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
clang::tidy::modernize::Confidence::Level
Level
Definition: LoopConvertUtils.h:249
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::modernize::LoopConvertCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition: LoopConvertCheck.h:23
clang::tidy::modernize::LoopConvertCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: LoopConvertCheck.cpp:494
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:29
clang::tidy::modernize::LoopConvertCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: LoopConvertCheck.cpp:500
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
SM
const SourceManager & SM
Definition: IncludeCleaner.cpp:140
clang::tidy::modernize::VariableNamer::NamingStyle
NamingStyle
Definition: LoopConvertUtils.h:430