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