Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:21

0001 //===--- FunctionCognitiveComplexityCheck.h - clang-tidy --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONCOGNITIVECOMPLEXITYCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONCOGNITIVECOMPLEXITYCHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 
0014 namespace clang::tidy::readability {
0015 
0016 /// Checks function Cognitive Complexity metric.
0017 ///
0018 /// There are the following configuration option:
0019 ///
0020 ///   * `Threshold` - flag functions with Cognitive Complexity exceeding
0021 ///     this number. The default is `25`.
0022 ///   * `DescribeBasicIncrements`- if set to `true`, then for each function
0023 ///     exceeding the complexity threshold the check will issue additional
0024 ///     diagnostics on every piece of code (loop, `if` statement, etc.) which
0025 ///     contributes to that complexity.
0026 //      Default is `true`
0027 ///   * `IgnoreMacros` - if set to `true`, the check will ignore code inside
0028 ///     macros. Default is `false`.
0029 ///
0030 /// For the user-facing documentation see:
0031 /// http://clang.llvm.org/extra/clang-tidy/checks/readability/function-cognitive-complexity.html
0032 class FunctionCognitiveComplexityCheck : public ClangTidyCheck {
0033 public:
0034   FunctionCognitiveComplexityCheck(StringRef Name, ClangTidyContext *Context);
0035 
0036   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0037   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0038   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0039   std::optional<TraversalKind> getCheckTraversalKind() const override {
0040     return TK_IgnoreUnlessSpelledInSource;
0041   }
0042 
0043 private:
0044   const unsigned Threshold;
0045   const bool DescribeBasicIncrements;
0046   const bool IgnoreMacros;
0047 };
0048 
0049 } // namespace clang::tidy::readability
0050 
0051 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONCOGNITIVECOMPLEXITYCHECK_H