blob: 7defccdb0b1eca28651eca9360f2177c0c846b76 [file] [log] [blame]
Alexander Kornienko1b677db2015-03-09 12:18:39 +00001//===--- FunctionSizeCheck.h - clang-tidy -----------------------*- C++ -*-===//
Benjamin Kramer6e195422014-09-15 12:48:25 +00002//
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
Alexander Kornienko1b677db2015-03-09 12:18:39 +000010#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
Benjamin Kramer6e195422014-09-15 12:48:25 +000012
13#include "../ClangTidy.h"
14
15namespace clang {
16namespace tidy {
Alexander Kornienko35ddae42014-10-15 10:51:57 +000017namespace readability {
Benjamin Kramer6e195422014-09-15 12:48:25 +000018
Alexander Kornienkof8ed0a82015-08-27 18:01:58 +000019/// Checks for large functions based on various metrics.
20///
21/// These options are supported:
22///
23/// * `LineThreshold` - flag functions exceeding this number of lines. The
24/// default is `-1` (ignore the number of lines).
25/// * `StatementThreshold` - flag functions exceeding this number of
26/// statements. This may differ significantly from the number of lines for
27/// macro-heavy code. The default is `800`.
28/// * `BranchThreshold` - flag functions exceeding this number of control
29/// statements. The default is `-1` (ignore the number of branches).
Roman Lebedeva1cee292017-06-09 14:22:10 +000030/// * `ParameterThreshold` - flag functions having a high number of
31/// parameters. The default is `-1` (ignore the number of parameters).
32/// * `NestingThreshold` - flag compound statements which create next nesting
33/// level after `NestingThreshold`. This may differ significantly from the
34/// expected value for macro-heavy code. The default is `-1` (ignore the
35/// nesting level).
Roman Lebedev4d37af02018-04-12 12:06:42 +000036/// * `VariableThreshold` - flag functions having a high number of variable
37/// declarations. The default is `-1` (ignore the number of variables).
Benjamin Kramer6e195422014-09-15 12:48:25 +000038class FunctionSizeCheck : public ClangTidyCheck {
39public:
40 FunctionSizeCheck(StringRef Name, ClangTidyContext *Context);
41
42 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
43 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
44 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
Benjamin Kramer6e195422014-09-15 12:48:25 +000045
46private:
Benjamin Kramer6e195422014-09-15 12:48:25 +000047 const unsigned LineThreshold;
48 const unsigned StatementThreshold;
49 const unsigned BranchThreshold;
Alexander Kornienko91086442017-03-01 10:17:32 +000050 const unsigned ParameterThreshold;
Roman Lebedeva1cee292017-06-09 14:22:10 +000051 const unsigned NestingThreshold;
Roman Lebedev4d37af02018-04-12 12:06:42 +000052 const unsigned VariableThreshold;
Benjamin Kramer6e195422014-09-15 12:48:25 +000053};
54
Alexander Kornienko35ddae42014-10-15 10:51:57 +000055} // namespace readability
Benjamin Kramer6e195422014-09-15 12:48:25 +000056} // namespace tidy
57} // namespace clang
58
Alexander Kornienko1b677db2015-03-09 12:18:39 +000059#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H