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

Method parse

lib/valueflow.cpp:6415–6440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6413
6414struct IteratorConditionHandler : SimpleConditionHandler {
6415 std::vector<Condition> parse(const Token* tok, const Settings& /*settings*/) const override {
6416 Condition cond;
6417
6418 if (Token::Match(tok, "==|!=")) {
6419 if (!tok->astOperand1() || !tok->astOperand2())
6420 return {};
6421
6422 constexpr ValueFlow::Value::ValueKind kind = ValueFlow::Value::ValueKind::Known;
6423 std::list<ValueFlow::Value> values = getIteratorValues(tok->astOperand1()->values(), &kind);
6424 if (!values.empty()) {
6425 cond.vartok = tok->astOperand2();
6426 } else {
6427 values = getIteratorValues(tok->astOperand2()->values(), &kind);
6428 if (!values.empty())
6429 cond.vartok = tok->astOperand1();
6430 }
6431 for (ValueFlow::Value& v:values) {
6432 v.setPossible();
6433 v.assumeCondition(tok);
6434 }
6435 cond.true_values = values;
6436 cond.false_values = std::move(values);
6437 }
6438
6439 return {std::move(cond)};
6440 }
6441};
6442
6443static void valueFlowIteratorInfer(TokenList& tokenlist, const Settings& settings)

Callers

nothing calls this directly

Calls 5

getIteratorValuesFunction · 0.85
astOperand1Method · 0.80
astOperand2Method · 0.80
assumeConditionMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected