ValueFlow: Refactoring setTokenValue()
This commit is contained in:
parent
3d5781743c
commit
9bdee7fce9
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue