1 //===--- 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 16 namespace clang { 17 namespace tidy { 18 namespace modernize { 19 20 class LoopConvertCheck : public ClangTidyCheck { 21 public: 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 27 private: 28 struct RangeDescriptor { 29 RangeDescriptor(); 30 bool ContainerNeedsDereference; 31 bool DerefByConstRef; 32 bool DerefByValue; 33 std::string ContainerString; 34 QualType ElemType; 35 }; 36 37 void getAliasRange(SourceManager &SM, SourceRange &DeclRange); 38 39 void doConversion(ASTContext *Context, const VarDecl *IndexVar, 40 const ValueDecl *MaybeContainer, const UsageResult &Usages, 41 const DeclStmt *AliasDecl, bool AliasUseRequired, 42 bool AliasFromForInit, const ForStmt *Loop, 43 RangeDescriptor Descriptor); 44 45 StringRef getContainerString(ASTContext *Context, const ForStmt *Loop, 46 const Expr *ContainerExpr); 47 48 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); 67 68 std::unique_ptr<TUTrackingInfo> TUInfo; 69 const unsigned long long MaxCopySize; 70 const Confidence::Level MinConfidence; 71 const VariableNamer::NamingStyle NamingStyle; 72 }; 73 74 } // namespace modernize 75 } // namespace tidy 76 } // namespace clang 77 78 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H 79