blob: 905a0d79e8494b433700a8428afb37436e8d08da [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).
Alexander Kornienko91086442017-03-01 10:17:32 +000030/// * `ParameterThreshold` - flag functions having a high number of parameters.
31/// The default is `6`.
Benjamin Kramer6e195422014-09-15 12:48:25 +000032class FunctionSizeCheck : public ClangTidyCheck {
33public:
34 FunctionSizeCheck(StringRef Name, ClangTidyContext *Context);
35
36 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
37 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
38 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
Benjamin Kramer6e195422014-09-15 12:48:25 +000039
40private:
Benjamin Kramer6e195422014-09-15 12:48:25 +000041 const unsigned LineThreshold;
42 const unsigned StatementThreshold;
43 const unsigned BranchThreshold;
Alexander Kornienko91086442017-03-01 10:17:32 +000044 const unsigned ParameterThreshold;
Benjamin Kramer6e195422014-09-15 12:48:25 +000045};
46
Alexander Kornienko35ddae42014-10-15 10:51:57 +000047} // namespace readability
Benjamin Kramer6e195422014-09-15 12:48:25 +000048} // namespace tidy
49} // namespace clang
50
Alexander Kornienko1b677db2015-03-09 12:18:39 +000051#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H