blob: f2bcf59691c43daf09fa9bfdca9c26062f8bbe61 [file] [log] [blame]
Alexander Kornienko04970842015-08-19 09:11:46 +00001//===--- LoopConvertCheck.h - clang-tidy-------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
12
13#include "../ClangTidy.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 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
24 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
25 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
26
27private:
Angel Garcia Gomezd930ef72015-09-08 09:01:21 +000028 struct RangeDescriptor {
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000029 RangeDescriptor();
Angel Garcia Gomezd930ef72015-09-08 09:01:21 +000030 bool ContainerNeedsDereference;
Angel Garcia Gomezbb9ca542015-09-11 10:02:07 +000031 bool DerefByConstRef;
Angel Garcia Gomezd930ef72015-09-08 09:01:21 +000032 bool DerefByValue;
33 bool IsTriviallyCopyable;
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000034 std::string ContainerString;
Angel Garcia Gomezd930ef72015-09-08 09:01:21 +000035 };
36
Alexander Kornienko04970842015-08-19 09:11:46 +000037 void doConversion(ASTContext *Context, const VarDecl *IndexVar,
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000038 const VarDecl *MaybeContainer, const UsageResult &Usages,
39 const DeclStmt *AliasDecl, bool AliasUseRequired,
40 bool AliasFromForInit, const ForStmt *Loop,
41 RangeDescriptor Descriptor);
Alexander Kornienko04970842015-08-19 09:11:46 +000042
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000043 StringRef getContainerString(ASTContext *Context, const ForStmt *Loop,
44 const Expr *ContainerExpr);
Alexander Kornienko04970842015-08-19 09:11:46 +000045
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000046 void getArrayLoopQualifiers(ASTContext *Context,
47 const ast_matchers::BoundNodes &Nodes,
48 const Expr *ContainerExpr,
49 const UsageResult &Usages,
50 RangeDescriptor &Descriptor);
51
52 void getIteratorLoopQualifiers(ASTContext *Context,
53 const ast_matchers::BoundNodes &Nodes,
54 RangeDescriptor &Descriptor);
55
56 void determineRangeDescriptor(ASTContext *Context,
57 const ast_matchers::BoundNodes &Nodes,
58 const ForStmt *Loop, LoopFixerKind FixerKind,
59 const Expr *ContainerExpr,
60 const UsageResult &Usages,
61 RangeDescriptor &Descriptor);
62
63 bool isConvertible(ASTContext *Context, const ast_matchers::BoundNodes &Nodes,
64 const ForStmt *Loop, LoopFixerKind FixerKind);
Angel Garcia Gomezd930ef72015-09-08 09:01:21 +000065
Alexander Kornienko04970842015-08-19 09:11:46 +000066 std::unique_ptr<TUTrackingInfo> TUInfo;
Angel Garcia Gomez8535c6c2015-09-24 17:02:19 +000067 const Confidence::Level MinConfidence;
68 const VariableNamer::NamingStyle NamingStyle;
Alexander Kornienko04970842015-08-19 09:11:46 +000069};
70
71} // namespace modernize
72} // namespace tidy
73} // namespace clang
74
75#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H