Refactoring: Use range for loops
This commit is contained in:
parent
d603a811bb
commit
0f3cc56c59
|
@ -608,11 +608,10 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
|
|
||||||
// !
|
// !
|
||||||
else if (parent->str() == "!") {
|
else if (parent->str() == "!") {
|
||||||
std::list<ValueFlow::Value>::const_iterator it;
|
for (const ValueFlow::Value &val : tok->values()) {
|
||||||
for (it = tok->values().begin(); it != tok->values().end(); ++it) {
|
if (!val.isIntValue())
|
||||||
if (!it->isIntValue())
|
|
||||||
continue;
|
continue;
|
||||||
ValueFlow::Value v(*it);
|
ValueFlow::Value v(val);
|
||||||
v.intvalue = !v.intvalue;
|
v.intvalue = !v.intvalue;
|
||||||
setTokenValue(parent, v, settings);
|
setTokenValue(parent, v, settings);
|
||||||
}
|
}
|
||||||
|
@ -620,11 +619,10 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
|
|
||||||
// ~
|
// ~
|
||||||
else if (parent->str() == "~") {
|
else if (parent->str() == "~") {
|
||||||
std::list<ValueFlow::Value>::const_iterator it;
|
for (const ValueFlow::Value &val : tok->values()) {
|
||||||
for (it = tok->values().begin(); it != tok->values().end(); ++it) {
|
if (!val.isIntValue())
|
||||||
if (!it->isIntValue())
|
|
||||||
continue;
|
continue;
|
||||||
ValueFlow::Value v(*it);
|
ValueFlow::Value v(val);
|
||||||
v.intvalue = ~v.intvalue;
|
v.intvalue = ~v.intvalue;
|
||||||
unsigned int bits = 0;
|
unsigned int bits = 0;
|
||||||
if (settings &&
|
if (settings &&
|
||||||
|
@ -643,12 +641,11 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
}
|
}
|
||||||
|
|
||||||
// unary minus
|
// unary minus
|
||||||
else if (parent->str() == "-" && !parent->astOperand2()) {
|
else if (parent->isUnaryOp("-")) {
|
||||||
std::list<ValueFlow::Value>::const_iterator it;
|
for (const ValueFlow::Value &val : tok->values()) {
|
||||||
for (it = tok->values().begin(); it != tok->values().end(); ++it) {
|
if (!val.isIntValue() && !val.isFloatValue())
|
||||||
if (!it->isIntValue() && !it->isFloatValue())
|
|
||||||
continue;
|
continue;
|
||||||
ValueFlow::Value v(*it);
|
ValueFlow::Value v(val);
|
||||||
if (v.isIntValue())
|
if (v.isIntValue())
|
||||||
v.intvalue = -v.intvalue;
|
v.intvalue = -v.intvalue;
|
||||||
else
|
else
|
||||||
|
@ -658,25 +655,25 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array element
|
// Array element
|
||||||
else if (parent->str() == "[" && parent->astOperand1() && parent->astOperand2()) {
|
else if (parent->str() == "[" && parent->isBinaryOp()) {
|
||||||
for (std::list<ValueFlow::Value>::const_iterator value1 = parent->astOperand1()->values().begin(); value1 != parent->astOperand1()->values().end(); ++value1) {
|
for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) {
|
||||||
if (!value1->isTokValue())
|
if (!value1.isTokValue())
|
||||||
continue;
|
continue;
|
||||||
for (std::list<ValueFlow::Value>::const_iterator value2 = parent->astOperand2()->values().begin(); value2 != parent->astOperand2()->values().end(); ++value2) {
|
for (const ValueFlow::Value &value2 : parent->astOperand2()->values()) {
|
||||||
if (!value2->isIntValue())
|
if (!value2.isIntValue())
|
||||||
continue;
|
continue;
|
||||||
if (value1->varId == 0U || value2->varId == 0U ||
|
if (value1.varId == 0U || value2.varId == 0U ||
|
||||||
(value1->varId == value2->varId && value1->varvalue == value2->varvalue)) {
|
(value1.varId == value2.varId && value1.varvalue == value2.varvalue)) {
|
||||||
ValueFlow::Value result(0);
|
ValueFlow::Value result(0);
|
||||||
result.condition = value1->condition ? value1->condition : value2->condition;
|
result.condition = value1.condition ? value1.condition : value2.condition;
|
||||||
result.setInconclusive(value1->isInconclusive() | value2->isInconclusive());
|
result.setInconclusive(value1.isInconclusive() | value2.isInconclusive());
|
||||||
result.varId = (value1->varId != 0U) ? value1->varId : value2->varId;
|
result.varId = (value1.varId != 0U) ? value1.varId : value2.varId;
|
||||||
result.varvalue = (result.varId == value1->varId) ? value1->intvalue : value2->intvalue;
|
result.varvalue = (result.varId == value1.varId) ? value1.intvalue : value2.intvalue;
|
||||||
if (value1->valueKind == value2->valueKind)
|
if (value1.valueKind == value2.valueKind)
|
||||||
result.valueKind = value1->valueKind;
|
result.valueKind = value1.valueKind;
|
||||||
if (value1->tokvalue->tokType() == Token::eString) {
|
if (value1.tokvalue->tokType() == Token::eString) {
|
||||||
const std::string s = value1->tokvalue->strValue();
|
const std::string s = value1.tokvalue->strValue();
|
||||||
const MathLib::bigint index = value2->intvalue;
|
const MathLib::bigint index = value2.intvalue;
|
||||||
if (index == s.size()) {
|
if (index == s.size()) {
|
||||||
result.intvalue = 0;
|
result.intvalue = 0;
|
||||||
setTokenValue(parent, result, settings);
|
setTokenValue(parent, result, settings);
|
||||||
|
@ -684,9 +681,9 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
result.intvalue = s[index];
|
result.intvalue = s[index];
|
||||||
setTokenValue(parent, result, settings);
|
setTokenValue(parent, result, settings);
|
||||||
}
|
}
|
||||||
} else if (value1->tokvalue->str() == "{") {
|
} else if (value1.tokvalue->str() == "{") {
|
||||||
MathLib::bigint index = value2->intvalue;
|
MathLib::bigint index = value2.intvalue;
|
||||||
const Token *element = value1->tokvalue->next();
|
const Token *element = value1.tokvalue->next();
|
||||||
while (index > 0 && element->str() != "}") {
|
while (index > 0 && element->str() != "}") {
|
||||||
if (element->str() == ",")
|
if (element->str() == ",")
|
||||||
--index;
|
--index;
|
||||||
|
|
Loading…
Reference in New Issue