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