68 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H11 12#include "../ClangTidyCheck.h"13 14namespace clang::tidy::readability {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. The21/// default is `-1` (ignore the number of lines).22/// * `StatementThreshold` - flag functions exceeding this number of23/// statements. This may differ significantly from the number of lines for24/// macro-heavy code. The default is `800`.25/// * `BranchThreshold` - flag functions exceeding this number of control26/// statements. The default is `-1` (ignore the number of branches).27/// * `ParameterThreshold` - flag functions having a high number of28/// parameters. The default is `-1` (ignore the number of parameters).29/// * `NestingThreshold` - flag compound statements which create next nesting30/// level after `NestingThreshold`. This may differ significantly from the31/// expected value for macro-heavy code. The default is `-1` (ignore the32/// nesting level).33/// * `VariableThreshold` - flag functions having a high number of variable34/// declarations. The default is `-1` (ignore the number of variables).35class FunctionSizeCheck : public ClangTidyCheck {36public:37 FunctionSizeCheck(StringRef Name, ClangTidyContext *Context);38 39 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;40 void registerMatchers(ast_matchers::MatchFinder *Finder) override;41 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;42 43private:44 const std::optional<unsigned> LineThreshold;45 const std::optional<unsigned> StatementThreshold;46 const std::optional<unsigned> BranchThreshold;47 const std::optional<unsigned> ParameterThreshold;48 const std::optional<unsigned> NestingThreshold;49 const std::optional<unsigned> VariableThreshold;50 const bool CountMemberInitAsStmt;51 52 static constexpr std::optional<unsigned> DefaultLineThreshold = std::nullopt;53 static constexpr std::optional<unsigned> DefaultStatementThreshold = 800U;54 static constexpr std::optional<unsigned> DefaultBranchThreshold =55 std::nullopt;56 static constexpr std::optional<unsigned> DefaultParameterThreshold =57 std::nullopt;58 static constexpr std::optional<unsigned> DefaultNestingThreshold =59 std::nullopt;60 static constexpr std::optional<unsigned> DefaultVariableThreshold =61 std::nullopt;62 static constexpr bool DefaultCountMemberInitAsStmt = true;63};64 65} // namespace clang::tidy::readability66 67#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONSIZECHECK_H68