blob: 1231cb139ea4edba7b989dea876e1c6df49ec885 [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).
Benjamin Kramer6e195422014-09-15 12:48:25 +000030class FunctionSizeCheck : public ClangTidyCheck {
31public:
32 FunctionSizeCheck(StringRef Name, ClangTidyContext *Context);
33
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 void onEndOfTranslationUnit() override;
38
39private:
40 struct FunctionInfo {
41 FunctionInfo() : Lines(0), Statements(0), Branches(0) {}
42 unsigned Lines;
43 unsigned Statements;
44 unsigned Branches;
45 };
46
47 const unsigned LineThreshold;
48 const unsigned StatementThreshold;
49 const unsigned BranchThreshold;
50
51 llvm::DenseMap<const FunctionDecl *, FunctionInfo> FunctionInfos;
52};
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