clang-tools 23.0.0git
FunctionSizeCheck.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
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/// * `IgnoreMacros` - if set to `true`, the check will not count statements,
36/// branches, nesting levels, or variable declarations inside macros. The
37/// default is `false`.
39public:
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;
45
46private:
47 const std::optional<unsigned> LineThreshold;
48 const std::optional<unsigned> StatementThreshold;
49 const std::optional<unsigned> BranchThreshold;
50 const std::optional<unsigned> ParameterThreshold;
51 const std::optional<unsigned> NestingThreshold;
52 const std::optional<unsigned> VariableThreshold;
53 const bool CountMemberInitAsStmt;
54 const bool IgnoreMacros;
55
56 static constexpr std::optional<unsigned> DefaultLineThreshold = std::nullopt;
57 static constexpr std::optional<unsigned> DefaultStatementThreshold = 800U;
58 static constexpr std::optional<unsigned> DefaultBranchThreshold =
59 std::nullopt;
60 static constexpr std::optional<unsigned> DefaultParameterThreshold =
61 std::nullopt;
62 static constexpr std::optional<unsigned> DefaultNestingThreshold =
63 std::nullopt;
64 static constexpr std::optional<unsigned> DefaultVariableThreshold =
65 std::nullopt;
66 static constexpr bool DefaultCountMemberInitAsStmt = true;
67 static constexpr bool DefaultIgnoreMacros = false;
68};
69
70} // namespace clang::tidy::readability
71
72#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
FunctionSizeCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
llvm::StringMap< ClangTidyValue > OptionMap