blob: 75ab25aa1220d14629e75bff3b7bdc31bec6ae48 [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;
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000033 std::string ContainerString;
Angel Garcia Gomezd8336f32015-10-22 13:23:46 +000034 QualType ElemType;
Angel Garcia Gomezd930ef72015-09-08 09:01:21 +000035 };
36
Angel Garcia Gomez90bf8952015-10-01 13:08:21 +000037 void getAliasRange(SourceManager &SM, SourceRange &DeclRange);
38
Alexander Kornienko04970842015-08-19 09:11:46 +000039 void doConversion(ASTContext *Context, const VarDecl *IndexVar,
Angel Garcia Gomez432ff5e2015-11-03 16:38:31 +000040 const ValueDecl *MaybeContainer, const UsageResult &Usages,
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000041 const DeclStmt *AliasDecl, bool AliasUseRequired,
42 bool AliasFromForInit, const ForStmt *Loop,
43 RangeDescriptor Descriptor);
Alexander Kornienko04970842015-08-19 09:11:46 +000044
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000045 StringRef getContainerString(ASTContext *Context, const ForStmt *Loop,
46 const Expr *ContainerExpr);
Alexander Kornienko04970842015-08-19 09:11:46 +000047
Angel Garcia Gomezf41a6312015-09-21 09:32:59 +000048 void getArrayLoopQualifiers(ASTContext *Context,
49 const ast_matchers::BoundNodes &Nodes,
50 const Expr *ContainerExpr,
51 const UsageResult &Usages,
52 RangeDescriptor &Descriptor);
53
54 void getIteratorLoopQualifiers(ASTContext *Context,
55 const ast_matchers::BoundNodes &Nodes,
56 RangeDescriptor &Descriptor);
57
58 void determineRangeDescriptor(ASTContext *Context,
59 const ast_matchers::BoundNodes &Nodes,
60 const ForStmt *Loop, LoopFixerKind FixerKind,
61 const Expr *ContainerExpr,
62 const UsageResult &Usages,
63 RangeDescriptor &Descriptor);
64
65 bool isConvertible(ASTContext *Context, const ast_matchers::BoundNodes &Nodes,
66 const ForStmt *Loop, LoopFixerKind FixerKind);
Angel Garcia Gomezd930ef72015-09-08 09:01:21 +000067
Alexander Kornienko04970842015-08-19 09:11:46 +000068 std::unique_ptr<TUTrackingInfo> TUInfo;
Angel Garcia Gomez68175a02015-10-30 09:37:57 +000069 const unsigned long long MaxCopySize;
Angel Garcia Gomez8535c6c2015-09-24 17:02:19 +000070 const Confidence::Level MinConfidence;
71 const VariableNamer::NamingStyle NamingStyle;
Alexander Kornienko04970842015-08-19 09:11:46 +000072};
73
74} // namespace modernize
75} // namespace tidy
76} // namespace clang
77
78#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H