clang-tools  3.8.0
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).
31 public:
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
StringHandle Name
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
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.
Definition: ClangTidy.h:102
FunctionSizeCheck(StringRef Name, ClangTidyContext *Context)
Checks for large functions based on various metrics.
std::map< std::string, std::string > OptionMap
ClangTidyContext & Context
Definition: ClangTidy.cpp:93
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.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
const NamedDecl * Result
Definition: USRFinder.cpp:121