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

Method skipNotAndCasts

lib/valueflow.cpp:4586–4608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4584 }
4585
4586 static Token* skipNotAndCasts(Token* tok, bool* inverted = nullptr)
4587 {
4588 for (; tok->astParent(); tok = tok->astParent()) {
4589 if (Token::simpleMatch(tok->astParent(), "!")) {
4590 if (inverted)
4591 *inverted ^= true;
4592 continue;
4593 }
4594 if (Token::Match(tok->astParent(), "==|!=")) {
4595 const Token* sibling = tok->astSibling();
4596 if (sibling->hasKnownIntValue() && (astIsBool(tok) || astIsBool(sibling))) {
4597 const bool value = !!sibling->getKnownIntValue();
4598 if (inverted)
4599 *inverted ^= value == Token::simpleMatch(tok->astParent(), "!=");
4600 continue;
4601 }
4602 }
4603 if (tok->astParent()->isCast() && astIsBool(tok->astParent()))
4604 continue;
4605 return tok;
4606 }
4607 return tok;
4608 }
4609
4610 static void fillFromPath(ProgramMemory& pm, const Token* top, MathLib::bigint path, const Settings& settings)
4611 {

Callers

nothing calls this directly

Calls 6

astIsBoolFunction · 0.85
astParentMethod · 0.80
getKnownIntValueMethod · 0.80
isCastMethod · 0.80
simpleMatchFunction · 0.70
hasKnownIntValueMethod · 0.45

Tested by

no test coverage detected