clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

FunctionSizeCheck.h
Go to the documentation of this file.
1 //===--- FunctionSizeCheck.h - clang-tidy -----------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
12
13 #include "../ClangTidy.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace readability {
18
19 /// Checks for large functions based on various metrics.
20 ///
21 /// These options are supported:
22 ///
23 /// * `LineThreshold` - flag functions exceeding this number of lines. The
24 /// default is `-1` (ignore the number of lines).
25 /// * `StatementThreshold` - flag functions exceeding this number of
26 /// statements. This may differ significantly from the number of lines for
27 /// macro-heavy code. The default is `800`.
28 /// * `BranchThreshold` - flag functions exceeding this number of control
29 /// statements. The default is `-1` (ignore the number of branches).
30 class FunctionSizeCheck : public ClangTidyCheck {
31 public:
32 FunctionSizeCheck(StringRef Name, ClangTidyContext *Context);
33
34 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
35 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
37 void onEndOfTranslationUnit() override;
38
39 private:
40 struct FunctionInfo {
41 FunctionInfo() : Lines(0), Statements(0), Branches(0) {}
42 unsigned Lines;
43 unsigned Statements;
44 unsigned Branches;
45 };
46
47 const unsigned LineThreshold;
48 const unsigned StatementThreshold;
49 const unsigned BranchThreshold;
50
51 llvm::DenseMap<const FunctionDecl *, FunctionInfo> FunctionInfos;
52 };
53
54 } // namespace readability
55 } // namespace tidy
56 } // namespace clang
57
58 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
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:25
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
clang::tidy::readability::FunctionSizeCheck::FunctionSizeCheck
FunctionSizeCheck(StringRef Name, ClangTidyContext *Context)
Definition: FunctionSizeCheck.cpp:19
clang::tidy::readability::FunctionSizeCheck
Checks for large functions based on various metrics.
Definition: FunctionSizeCheck.h:30
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:82
Context
ClangTidyContext & Context
Definition: ClangTidy.cpp:93
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:124
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:44
clang::tidy::readability::FunctionSizeCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Definition: FunctionSizeCheck.cpp:31
clang::tidy::readability::FunctionSizeCheck::onEndOfTranslationUnit
void onEndOfTranslationUnit() override
Definition: FunctionSizeCheck.cpp:70
Result
const NamedDecl * Result
Definition: USRFinder.cpp:121