ValueFlow: Refactoring setTokenValue()

This commit is contained in:
Daniel Marjamäki 2015-07-17 09:46:31 +02:00
parent 3d5781743c
commit 9bdee7fce9
1 changed files with 19 additions and 8 deletions

View File

@ -286,8 +286,8 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign
return false; return false;
} }
/** set ValueFlow value and perform calculations if possible */ /** Add token value. Return true if value is added. */
static void setTokenValue(Token* tok, const ValueFlow::Value &value) static bool addValue(Token *tok, const ValueFlow::Value &value)
{ {
// if value already exists, don't add it again // if value already exists, don't add it again
std::list<ValueFlow::Value>::iterator it; std::list<ValueFlow::Value>::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 // same value, but old value is inconclusive so replace it
if (it->inconclusive && !value.inconclusive) { if (it->inconclusive && !value.inconclusive) {
*it = value; *it = value;
if (it->varId == 0)
it->varId = tok->varId();
break; break;
} }
// Same value already exists, don't add new value // Same value already exists, don't add new value
return; return false;
} }
// Add value
if (it == tok->values.end()) { if (it == tok->values.end()) {
tok->values.push_back(value); ValueFlow::Value v(value);
it = tok->values.end(); if (v.varId == 0)
--it; v.varId = tok->varId();
if (it->varId == 0) tok->values.push_back(v);
it->varId = tok->varId();
} }
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<Token*>(tok->astParent()); Token *parent = const_cast<Token*>(tok->astParent());
if (!parent) if (!parent)
return; return;