From b1c8d81bcc8a94dc410ca31170acef76a2ed21c7 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Mon, 17 Jun 2019 13:17:45 +0200 Subject: [PATCH] Refactoring; Use range for loop (#1900) --- test/testvalueflow.cpp | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index aae831172..c9af0557e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -151,9 +151,8 @@ private: for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { - std::list::const_iterator it; - for (it = tok->values().begin(); it != tok->values().end(); ++it) { - if (it->isIntValue() && it->intvalue == value) + for (const ValueFlow::Value &v : tok->values()) { + if (v.isIntValue() && v.intvalue == value) return true; } } @@ -170,9 +169,8 @@ private: for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { - std::list::const_iterator it; - for (it = tok->values().begin(); it != tok->values().end(); ++it) { - if (it->isFloatValue() && it->floatValue >= value - diff && it->floatValue <= value + diff) + for (const ValueFlow::Value &v : tok->values()) { + if (v.isFloatValue() && v.floatValue >= value - diff && v.floatValue <= value + diff) return true; } } @@ -192,11 +190,10 @@ private: continue; std::ostringstream ostr; - std::list::const_iterator it; - for (it = tok->values().begin(); it != tok->values().end(); ++it) { - for (ValueFlow::Value::ErrorPath::const_iterator ep = it->errorPath.begin(); ep != it->errorPath.end(); ++ep) { - const Token *eptok = ep->first; - const std::string &msg = ep->second; + for (const ValueFlow::Value &v : tok->values()) { + for (const ValueFlow::Value::ErrorPathItem &ep : v.errorPath) { + const Token *eptok = ep.first; + const std::string &msg = ep.second; ostr << eptok->linenr() << ',' << msg << '\n'; } } @@ -214,9 +211,8 @@ private: for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { - std::list::const_iterator it; - for (it = tok->values().begin(); it != tok->values().end(); ++it) { - if (it->valueType == type && Token::simpleMatch(it->tokvalue, value)) + for (const ValueFlow::Value &v : tok->values()) { + if (v.valueType == type && Token::simpleMatch(v.tokvalue, value)) return true; } } @@ -251,9 +247,8 @@ private: for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { - std::list::const_iterator it; - for (it = tok->values().begin(); it != tok->values().end(); ++it) { - if (it->isMovedValue() && it->moveKind == moveKind) + for (const ValueFlow::Value &v : tok->values()) { + if (v.isMovedValue() && v.moveKind == moveKind) return true; } } @@ -270,9 +265,8 @@ private: for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { - std::list::const_iterator it; - for (it = tok->values().begin(); it != tok->values().end(); ++it) { - if (it->isIntValue() && it->intvalue == value && it->condition) + for (const ValueFlow::Value &v : tok->values()) { + if (v.isIntValue() && v.intvalue == value && v.condition) return true; } } @@ -2928,9 +2922,8 @@ private: } bool isNotKnownValues(const char code[], const char str[]) { - const std::list values = tokenValues(code, str); - for (std::list::const_iterator it = values.begin(); it != values.end(); ++it) { - if (it->isKnown()) + for (const ValueFlow::Value &v : tokenValues(code, str)) { + if (v.isKnown()) return false; } return true;