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

Function getConditionVariable

lib/valueflow.cpp:4964–4980  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4962}
4963
4964static const Token* getConditionVariable(const Token* tok)
4965{
4966 if (tok->str() == "!")
4967 return tok->astOperand1();
4968
4969 if (const Token* parent = tok->astParent()) {
4970 if (Token::Match(parent, "%oror%|&&|?") ||
4971 Token::Match(parent->previous(), "if|while (") ||
4972 (parent->str() == ";" && astIsLHS(tok) && Token::simpleMatch(parent->astParent(), ";"))) { // for loop condition
4973 if (Token::simpleMatch(tok, "="))
4974 return tok->astOperand1();
4975 if (!Token::Match(tok, "%comp%|%assign%"))
4976 return tok;
4977 }
4978 }
4979 return nullptr;
4980}
4981
4982struct SimpleConditionHandler : ConditionHandler {
4983 std::vector<Condition> parse(const Token* tok, const Settings& /*settings*/) const override {

Callers 1

parseMethod · 0.85

Calls 5

astIsLHSFunction · 0.85
astOperand1Method · 0.80
astParentMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected