| 1 |
//===--- FunctionSizeCheck.h - clang-tidy -----------------------*- C++ -*-===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H |
| 11 |
|
| 12 |
#include "../ClangTidyCheck.h" |
| 13 |
|
| 14 |
namespace clang::tidy::readability { |
| 15 |
|
| 16 |
/// Checks for large functions based on various metrics. |
| 17 |
/// |
| 18 |
/// These options are supported: |
| 19 |
/// |
| 20 |
/// * `LineThreshold` - flag functions exceeding this number of lines. The |
| 21 |
/// default is `-1` (ignore the number of lines). |
| 22 |
/// * `StatementThreshold` - flag functions exceeding this number of |
| 23 |
/// statements. This may differ significantly from the number of lines for |
| 24 |
/// macro-heavy code. The default is `800`. |
| 25 |
/// * `BranchThreshold` - flag functions exceeding this number of control |
| 26 |
/// statements. The default is `-1` (ignore the number of branches). |
| 27 |
/// * `ParameterThreshold` - flag functions having a high number of |
| 28 |
/// parameters. The default is `-1` (ignore the number of parameters). |
| 29 |
/// * `NestingThreshold` - flag compound statements which create next nesting |
| 30 |
/// level after `NestingThreshold`. This may differ significantly from the |
| 31 |
/// expected value for macro-heavy code. The default is `-1` (ignore the |
| 32 |
/// nesting level). |
| 33 |
/// * `VariableThreshold` - flag functions having a high number of variable |
| 34 |
/// declarations. The default is `-1` (ignore the number of variables). |
| 35 |
class FunctionSizeCheck : public ClangTidyCheck { |
| 36 |
public: |
| 37 |
FunctionSizeCheck(StringRef Name, ClangTidyContext *Context); |
| 38 |
|
| 39 |
void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
| 40 |
void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 41 |
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 42 |
|
| 43 |
private: |
| 44 |
const unsigned LineThreshold; |
| 45 |
const unsigned StatementThreshold; |
| 46 |
const unsigned BranchThreshold; |
| 47 |
const unsigned ParameterThreshold; |
| 48 |
const unsigned NestingThreshold; |
| 49 |
const unsigned VariableThreshold; |
| 50 |
}; |
| 51 |
|
| 52 |
} // namespace clang::tidy::readability |
| 53 |
|
| 54 |
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H |