clang-tools 20.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
16namespace clang::tidy::modernize {
17
19public:
20 LoopConvertCheck(StringRef Name, ClangTidyContext *Context);
21 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
22 return LangOpts.CPlusPlus;
23 }
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;
29
30private:
31 struct RangeDescriptor {
32 RangeDescriptor() = default;
33 bool ContainerNeedsDereference = false;
34 bool DerefByConstRef = false;
35 bool DerefByValue = false;
36 std::string ContainerString;
37 QualType ElemType;
38 bool NeedsReverseCall = false;
39 };
40
41 void getAliasRange(SourceManager &SM, SourceRange &DeclRange);
42
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);
48
49 StringRef getContainerString(ASTContext *Context, const ForStmt *Loop,
50 const Expr *ContainerExpr);
51
52 void getArrayLoopQualifiers(ASTContext *Context,
53 const ast_matchers::BoundNodes &Nodes,
54 const Expr *ContainerExpr,
55 const UsageResult &Usages,
56 RangeDescriptor &Descriptor);
57
58 void getIteratorLoopQualifiers(ASTContext *Context,
59 const ast_matchers::BoundNodes &Nodes,
60 RangeDescriptor &Descriptor);
61
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);
68
69 bool isConvertible(ASTContext *Context, const ast_matchers::BoundNodes &Nodes,
70 const ForStmt *Loop, LoopFixerKind FixerKind);
71
72 StringRef getReverseFunction() const;
73 StringRef getReverseHeader() const;
74
75 std::unique_ptr<TUTrackingInfo> TUInfo;
76 const unsigned long long MaxCopySize;
77 const Confidence::Level MinConfidence;
78 const VariableNamer::NamingStyle NamingStyle;
80 bool UseReverseRanges;
81 const bool UseCxx20IfAvailable;
82 std::string ReverseFunction;
83 std::string ReverseHeader;
84};
85
86} // namespace clang::tidy::modernize
87
88#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Produces fixes to insert specified includes to source files, if not yet present.
llvm::SmallVector< Usage, 8 > UsageResult
llvm::StringMap< ClangTidyValue > OptionMap