blob: d85dbc92cc59fd2da4313e00be34cae7ecb04795 [file] [log] [blame]
Alexander Kornienko1b677db2015-03-09 12:18:39 +00001//===--- FunctionSizeCheck.h - clang-tidy -----------------------*- C++ -*-===//
Benjamin Kramer6e195422014-09-15 12:48:25 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Benjamin Kramer6e195422014-09-15 12:48:25 +00006//
7//===----------------------------------------------------------------------===//
8
Alexander Kornienko1b677db2015-03-09 12:18:39 +00009#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
Benjamin Kramer6e195422014-09-15 12:48:25 +000011
Alexander Kornienko478fc5c2019-03-25 12:38:26 +000012#include "../ClangTidyCheck.h"
Benjamin Kramer6e195422014-09-15 12:48:25 +000013
14namespace clang {
15namespace tidy {
Alexander Kornienko35ddae42014-10-15 10:51:57 +000016namespace readability {
Benjamin Kramer6e195422014-09-15 12:48:25 +000017
Alexander Kornienkof8ed0a82015-08-27 18:01:58 +000018/// 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).
Roman Lebedeva1cee292017-06-09 14:22:10 +000029/// * `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).
Roman Lebedev4d37af02018-04-12 12:06:42 +000035/// * `VariableThreshold` - flag functions having a high number of variable
36/// declarations. The default is `-1` (ignore the number of variables).
Benjamin Kramer6e195422014-09-15 12:48:25 +000037class FunctionSizeCheck : public ClangTidyCheck {
38public:
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;
Benjamin Kramer6e195422014-09-15 12:48:25 +000044
45private:
Benjamin Kramer6e195422014-09-15 12:48:25 +000046 const unsigned LineThreshold;
47 const unsigned StatementThreshold;
48 const unsigned BranchThreshold;
Alexander Kornienko91086442017-03-01 10:17:32 +000049 const unsigned ParameterThreshold;
Roman Lebedeva1cee292017-06-09 14:22:10 +000050 const unsigned NestingThreshold;
Roman Lebedev4d37af02018-04-12 12:06:42 +000051 const unsigned VariableThreshold;
Benjamin Kramer6e195422014-09-15 12:48:25 +000052};
53
Alexander Kornienko35ddae42014-10-15 10:51:57 +000054} // namespace readability
Benjamin Kramer6e195422014-09-15 12:48:25 +000055} // namespace tidy
56} // namespace clang
57
Alexander Kornienko1b677db2015-03-09 12:18:39 +000058#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H