From 3d5781743c2c04393509b27e8e90e4d6e25f6584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 16 Jul 2015 21:17:44 +0200 Subject: [PATCH] ValueFlow: Restore handling of not --- lib/valueflow.cpp | 12 ++++++++++++ test/testvalueflow.cpp | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 31154e5d4..83c30a245 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -407,6 +407,18 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value) } } + // ! + else if (parent->str() == "!") { + std::list::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::const_iterator value1, value2; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index dd8a54c12..83ce94876 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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"