Lines Matching +full:method +full:- +full:complexity
1 //===--- FunctionCognitiveComplexityCheck.cpp - clang-tidy ------*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
45 // or user-facing docs at
46 // http://clang.llvm.org/extra/clang-tidy/checks/readability-function-cognitive-complexity.html
51 // B1, increases cognitive complexity (by 1)
60 // * each method in a recursion cycle (not implemented)
75 // B3, increases cognitive complexity by the current nesting level
100 // information - what message to output, how much of an increment did this
130 // Based on the publicly-avaliable numbers for some big open-source projects
140 // Yes, 25 is a magic number. This is the seemingly-sane default for the
141 // upper limit for function cognitive complexity. Thus it would make sense
144 // The grand total Cognitive Complexity of the function.
147 // The function used to store new increment, calculate the total complexity.
229 --CurrentNestingLevel; in TraverseStmtWithIncreasedNestingLevel()
236 --CurrentNestingLevel; in TraverseDeclWithIncreasedNestingLevel()
249 // "If" increases cognitive complexity. in TraverseIfStmt()
260 CC.account(Node->getIfLoc(), CurrentNestingLevel, Reasons); in TraverseIfStmt()
269 if (!TraverseStmt(Node->getInit())) in TraverseIfStmt()
272 if (!TraverseStmt(Node->getCond())) in TraverseIfStmt()
275 if (!TraverseStmtWithIncreasedNestingLevel(Node->getInit())) in TraverseIfStmt()
278 if (!TraverseStmtWithIncreasedNestingLevel(Node->getCond())) in TraverseIfStmt()
283 if (!TraverseStmtWithIncreasedNestingLevel(Node->getThen())) in TraverseIfStmt()
286 if (!Node->getElse()) in TraverseIfStmt()
289 if (auto *E = dyn_cast<IfStmt>(Node->getElse())) in TraverseIfStmt()
297 // "Else" increases cognitive complexity. in TraverseIfStmt()
304 CC.account(Node->getElseLoc(), CurrentNestingLevel, Reasons); in TraverseIfStmt()
308 return TraverseStmtWithIncreasedNestingLevel(Node->getElse()); in TraverseIfStmt()
311 // The currently-being-processed stack entry, which is always the top.
315 // from the previous one, then the cognitive complexity is increased.
317 if (!Op || !Op->isLogicalOp()) in TraverseBinaryOperator()
326 if (!CurrentBinaryOperator || Op->getOpcode() != CurrentBinaryOperator) in TraverseBinaryOperator()
327 CC.account(Op->getOperatorLoc(), CurrentNestingLevel, in TraverseBinaryOperator()
335 CurrentBinaryOperator = Op->getOpcode(); in TraverseBinaryOperator()
348 // no Node-handling is needed. in TraverseCallExpr()
371 SourceLocation Location = Node->getBeginLoc(); in TraverseStmt()
375 switch (Node->getStmtClass()) { in TraverseStmt()
377 // FIXME: "each method in a recursion cycle" Increment is not implemented. in TraverseStmt()
390 // break LABEL, continue LABEL increase cognitive complexity, in TraverseStmt()
392 // Regular break/continue do not increase cognitive complexity. in TraverseStmt()
398 switch (Node->getStmtClass()) { in TraverseStmt()
419 switch (Node->getStmtClass()) { in TraverseStmt()
434 if (Node->getStmtClass() == Stmt::ConditionalOperatorClass) { in TraverseStmt()
439 Location = COp->getQuestionLoc(); in TraverseStmt()
457 // definition (e.g. constructor, destructor, method), the Cognitive Complexity
460 // increased. Thus that parameter is there and is used to fall-through
468 switch (Node->getKind()) { in TraverseDecl()
481 CC.account(Node->getBeginLoc(), CurrentNestingLevel, in TraverseDecl()
503 Finder->addMatcher( in registerMatchers()
514 assert(Func->hasBody() && "The matchers should only match the functions that " in check()
515 "have user-provided body."); in check()
523 diag(Func->getLocation(), in check()
524 "function %0 has cognitive complexity of %1 (threshold %2)") in check()
527 // Output all the basic increments of complexity. in check()