From 9bdee7fce9f414fe1b00c04b9ba87f24e53b3a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 17 Jul 2015 09:46:31 +0200 Subject: [PATCH] ValueFlow: Refactoring setTokenValue() --- lib/valueflow.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 83c30a245..6d984f591 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -286,8 +286,8 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign return false; } -/** set ValueFlow value and perform calculations if possible */ -static void setTokenValue(Token* tok, const ValueFlow::Value &value) +/** Add token value. Return true if value is added. */ +static bool addValue(Token *tok, const ValueFlow::Value &value) { // if value already exists, don't add it again std::list::iterator it; @@ -305,21 +305,32 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value) // same value, but old value is inconclusive so replace it if (it->inconclusive && !value.inconclusive) { *it = value; + if (it->varId == 0) + it->varId = tok->varId(); break; } // Same value already exists, don't add new value - return; + return false; } + // Add value if (it == tok->values.end()) { - tok->values.push_back(value); - it = tok->values.end(); - --it; - if (it->varId == 0) - it->varId = tok->varId(); + ValueFlow::Value v(value); + if (v.varId == 0) + v.varId = tok->varId(); + tok->values.push_back(v); } + return true; +} + +/** set ValueFlow value and perform calculations if possible */ +static void setTokenValue(Token* tok, const ValueFlow::Value &value) +{ + if (!addValue(tok,value)) + return; + Token *parent = const_cast(tok->astParent()); if (!parent) return;