ValueFlow: Restore handling of not

This commit is contained in:
Daniel Marjamäki 2015-07-16 21:17:44 +02:00
parent 15a8e4d2df
commit 3d5781743c
2 changed files with 21 additions and 0 deletions

View File

@ -407,6 +407,18 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
}
}
// !
else if (parent->str() == "!") {
std::list<ValueFlow::Value>::const_iterator it;
for (it = tok->values.begin(); it != tok->values.end(); ++it) {
if (it->tokvalue)
continue;
ValueFlow::Value v(*it);
v.intvalue = !v.intvalue;
setTokenValue(parent, v);
}
}
// Array element
else if (parent->str() == "[" && parent->astOperand1() && parent->astOperand2()) {
std::list<ValueFlow::Value>::const_iterator value1, value2;

View File

@ -265,6 +265,15 @@ private:
ASSERT_EQUALS(2, values.front().intvalue);
ASSERT_EQUALS(3, values.back().intvalue);
// !
code = "void f(int x) {\n"
" a = !x;\n"
" if (x==0) {}\n"
"}";
values = tokenValues(code,"!");
ASSERT_EQUALS(1U, values.size());
ASSERT_EQUALS(1, values.back().intvalue);
// function call => calculation
code = "void f(int x) {\n"
" a = x + 8;\n"