FunctionSizeCheck.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //===--- FunctionSizeCheck.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_READABILITY_FUNCTIONSIZECHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::readability {
  12. /// Checks for large functions based on various metrics.
  13. ///
  14. /// These options are supported:
  15. ///
  16. /// * `LineThreshold` - flag functions exceeding this number of lines. The
  17. /// default is `-1` (ignore the number of lines).
  18. /// * `StatementThreshold` - flag functions exceeding this number of
  19. /// statements. This may differ significantly from the number of lines for
  20. /// macro-heavy code. The default is `800`.
  21. /// * `BranchThreshold` - flag functions exceeding this number of control
  22. /// statements. The default is `-1` (ignore the number of branches).
  23. /// * `ParameterThreshold` - flag functions having a high number of
  24. /// parameters. The default is `-1` (ignore the number of parameters).
  25. /// * `NestingThreshold` - flag compound statements which create next nesting
  26. /// level after `NestingThreshold`. This may differ significantly from the
  27. /// expected value for macro-heavy code. The default is `-1` (ignore the
  28. /// nesting level).
  29. /// * `VariableThreshold` - flag functions having a high number of variable
  30. /// declarations. The default is `-1` (ignore the number of variables).
  31. class FunctionSizeCheck : public ClangTidyCheck {
  32. public:
  33. FunctionSizeCheck(StringRef Name, ClangTidyContext *Context);
  34. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  35. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  36. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  37. private:
  38. const unsigned LineThreshold;
  39. const unsigned StatementThreshold;
  40. const unsigned BranchThreshold;
  41. const unsigned ParameterThreshold;
  42. const unsigned NestingThreshold;
  43. const unsigned VariableThreshold;
  44. };
  45. } // namespace clang::tidy::readability
  46. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H