Alexander Kornienko | 1b677db | 2015-03-09 12:18:39 +0000 | [diff] [blame] | 1 | //===--- FunctionSizeCheck.h - clang-tidy -----------------------*- C++ -*-===// |
Benjamin Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 2 | // |
| 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 Kornienko | 1b677db | 2015-03-09 12:18:39 +0000 | [diff] [blame] | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H |
| 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H |
Benjamin Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 12 | |
| 13 | #include "../ClangTidy.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
Alexander Kornienko | 35ddae4 | 2014-10-15 10:51:57 +0000 | [diff] [blame] | 17 | namespace readability { |
Benjamin Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 18 | |
Alexander Kornienko | f8ed0a8 | 2015-08-27 18:01:58 +0000 | [diff] [blame] | 19 | /// 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 Lebedev | a1cee29 | 2017-06-09 14:22:10 +0000 | [diff] [blame] | 30 | /// * `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 Lebedev | 4d37af0 | 2018-04-12 12:06:42 +0000 | [diff] [blame^] | 36 | /// * `VariableThreshold` - flag functions having a high number of variable |
| 37 | /// declarations. The default is `-1` (ignore the number of variables). |
Benjamin Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 38 | class FunctionSizeCheck : public ClangTidyCheck { |
| 39 | public: |
| 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 Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 45 | |
| 46 | private: |
Benjamin Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 47 | const unsigned LineThreshold; |
| 48 | const unsigned StatementThreshold; |
| 49 | const unsigned BranchThreshold; |
Alexander Kornienko | 9108644 | 2017-03-01 10:17:32 +0000 | [diff] [blame] | 50 | const unsigned ParameterThreshold; |
Roman Lebedev | a1cee29 | 2017-06-09 14:22:10 +0000 | [diff] [blame] | 51 | const unsigned NestingThreshold; |
Roman Lebedev | 4d37af0 | 2018-04-12 12:06:42 +0000 | [diff] [blame^] | 52 | const unsigned VariableThreshold; |
Benjamin Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
Alexander Kornienko | 35ddae4 | 2014-10-15 10:51:57 +0000 | [diff] [blame] | 55 | } // namespace readability |
Benjamin Kramer | 6e19542 | 2014-09-15 12:48:25 +0000 | [diff] [blame] | 56 | } // namespace tidy |
| 57 | } // namespace clang |
| 58 | |
Alexander Kornienko | 1b677db | 2015-03-09 12:18:39 +0000 | [diff] [blame] | 59 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H |