MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / reentersLoop

Function reentersLoop

lib/forwardanalyzer.cpp:412–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410 }
411
412 bool reentersLoop(Token* endBlock, const Token* condTok, const Token* stepTok) const {
413 if (!condTok)
414 return true;
415 if (Token::simpleMatch(condTok, ":"))
416 return true;
417 bool stepChangesCond = false;
418 if (stepTok) {
419 std::pair<const Token*, const Token*> exprToks = stepTok->findExpressionStartEndTokens();
420 if (exprToks.first != nullptr && exprToks.second != nullptr)
421 stepChangesCond |=
422 findExpressionChanged(condTok, exprToks.first, exprToks.second->next(), settings) != nullptr;
423 }
424 const bool bodyChangesCond = findExpressionChanged(condTok, endBlock->link(), endBlock, settings);
425 // Check for mutation in the condition
426 const bool condChanged =
427 nullptr != findAstNode(condTok, [&](const Token* tok) {
428 return isVariableChanged(tok, 0, settings);
429 });
430 const bool changed = stepChangesCond || bodyChangesCond || condChanged;
431 if (!changed)
432 return true;
433 ForwardTraversal ft = fork(true);
434 ft.updateScope(endBlock);
435 return ft.isConditionTrue(condTok) && bodyChangesCond;
436 }
437
438 Progress updateInnerLoop(Token* endBlock, Token* stepTok, Token* condTok) {
439 loopEnds.push_back(endBlock);

Callers 1

updateLoopFunction · 0.85

Calls 8

findExpressionChangedFunction · 0.85
findAstNodeFunction · 0.85
isVariableChangedFunction · 0.85
forkFunction · 0.85
nextMethod · 0.80
simpleMatchFunction · 0.70
updateScopeMethod · 0.45

Tested by

no test coverage detected