clang-tools 10.0.0

FunctionSizeCheck.h
Go to the documentation of this file.
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 {
15 namespace tidy {
16 namespace readability {
17
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).
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).
35 /// * `VariableThreshold` - flag functions having a high number of variable
36 /// declarations. The default is `-1` (ignore the number of variables).
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;
44
45 private:
46 const unsigned LineThreshold;
47 const unsigned StatementThreshold;
48 const unsigned BranchThreshold;
49 const unsigned ParameterThreshold;
50 const unsigned NestingThreshold;
51 const unsigned VariableThreshold;
52 };
53
54 } // namespace readability
55 } // namespace tidy
56 } // namespace clang
57
58 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
clang::tidy::readability::FunctionSizeCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: FunctionSizeCheck.cpp:137
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::readability::FunctionSizeCheck::FunctionSizeCheck
FunctionSizeCheck(StringRef Name, ClangTidyContext *Context)
Definition: FunctionSizeCheck.cpp:128
clang::tidy::readability::FunctionSizeCheck
Checks for large functions based on various metrics.
Definition: FunctionSizeCheck.h:37
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
clang::tidy::readability::FunctionSizeCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: FunctionSizeCheck.cpp:155
clang::tidy::readability::FunctionSizeCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: FunctionSizeCheck.cpp:146