clang-tools  12.0.0git
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).
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
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Base class for all clang-tidy checks.
FunctionSizeCheck(StringRef Name, ClangTidyContext *Context)
Checks for large functions based on various metrics.
static constexpr llvm::StringLiteral Name
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
std::map< std::string, ClangTidyValue > OptionMap
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.