LoopConvertCheck.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
  10. #include "../ClangTidyCheck.h"
  11. #include "../utils/IncludeInserter.h"
  12. #include "LoopConvertUtils.h"
  13. namespace clang::tidy::modernize {
  14. class LoopConvertCheck : public ClangTidyCheck {
  15. public:
  16. LoopConvertCheck(StringRef Name, ClangTidyContext *Context);
  17. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  18. return LangOpts.CPlusPlus;
  19. }
  20. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  21. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  22. void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
  23. Preprocessor *ModuleExpanderPP) override;
  24. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  25. private:
  26. struct RangeDescriptor {
  27. RangeDescriptor();
  28. bool ContainerNeedsDereference;
  29. bool DerefByConstRef;
  30. bool DerefByValue;
  31. std::string ContainerString;
  32. QualType ElemType;
  33. bool NeedsReverseCall;
  34. };
  35. void getAliasRange(SourceManager &SM, SourceRange &DeclRange);
  36. void doConversion(ASTContext *Context, const VarDecl *IndexVar,
  37. const ValueDecl *MaybeContainer, const UsageResult &Usages,
  38. const DeclStmt *AliasDecl, bool AliasUseRequired,
  39. bool AliasFromForInit, const ForStmt *Loop,
  40. RangeDescriptor Descriptor);
  41. StringRef getContainerString(ASTContext *Context, const ForStmt *Loop,
  42. const Expr *ContainerExpr);
  43. void getArrayLoopQualifiers(ASTContext *Context,
  44. const ast_matchers::BoundNodes &Nodes,
  45. const Expr *ContainerExpr,
  46. const UsageResult &Usages,
  47. RangeDescriptor &Descriptor);
  48. void getIteratorLoopQualifiers(ASTContext *Context,
  49. const ast_matchers::BoundNodes &Nodes,
  50. RangeDescriptor &Descriptor);
  51. void determineRangeDescriptor(ASTContext *Context,
  52. const ast_matchers::BoundNodes &Nodes,
  53. const ForStmt *Loop, LoopFixerKind FixerKind,
  54. const Expr *ContainerExpr,
  55. const UsageResult &Usages,
  56. RangeDescriptor &Descriptor);
  57. bool isConvertible(ASTContext *Context, const ast_matchers::BoundNodes &Nodes,
  58. const ForStmt *Loop, LoopFixerKind FixerKind);
  59. StringRef getReverseFunction() const;
  60. StringRef getReverseHeader() const;
  61. std::unique_ptr<TUTrackingInfo> TUInfo;
  62. const unsigned long long MaxCopySize;
  63. const Confidence::Level MinConfidence;
  64. const VariableNamer::NamingStyle NamingStyle;
  65. utils::IncludeInserter Inserter;
  66. bool UseReverseRanges;
  67. const bool UseCxx20IfAvailable;
  68. std::string ReverseFunction;
  69. std::string ReverseHeader;
  70. };
  71. } // namespace clang::tidy::modernize
  72. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H