ErrorPath: More information about assignments

This commit is contained in:
Daniel Marjamäki 2017-05-16 23:12:35 +02:00
parent ecb3f0a934
commit cd53d10970
3 changed files with 30 additions and 7 deletions

View File

@ -221,8 +221,12 @@ public:
unsigned int line;
unsigned int fileNumber;
std::string getinfo() const { return _info; }
void setinfo(const std::string &i) { _info = i; }
std::string getinfo() const {
return _info;
}
void setinfo(const std::string &i) {
_info = i;
}
private:
std::string _file;

View File

@ -1971,8 +1971,12 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat
continue;
std::list<ValueFlow::Value> values = tok->astOperand2()->values();
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end(); ++it)
it->errorPath.push_back(ErrorPathItem(tok->astOperand2(),"assignment"));
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end(); ++it) {
std::string info = "Assignment";
if (it->isIntValue())
info += ", integer value " + MathLib::toString(it->intvalue);
it->errorPath.push_back(ErrorPathItem(tok->astOperand2(), info));
}
const bool constValue = tok->astOperand2()->isNumber();
if (tokenlist->isCPP() && Token::Match(var->typeStartToken(), "bool|_Bool")) {
@ -2926,6 +2930,23 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab
}
}
ValueFlow::Value::Value(const Token *c, long long val)
: valueType(INT),
intvalue(val),
tokvalue(nullptr),
floatValue(0.0),
moveKind(NonMovedVariable),
varvalue(val),
condition(c),
varId(0U),
conditional(false),
inconclusive(false),
defaultArg(false),
valueKind(ValueKind::Possible)
{
errorPath.push_back(ErrorPathItem(c, "Condition '" + c->expressionString() + "'"));
}
const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(const Token *expr, const Settings *settings)
{
if (expr && expr->values().empty()) {

View File

@ -38,9 +38,7 @@ namespace ValueFlow {
typedef std::list<ErrorPathItem> ErrorPath;
explicit Value(long long val = 0) : valueType(INT), intvalue(val), tokvalue(nullptr), floatValue(0.0), moveKind(NonMovedVariable), varvalue(val), condition(0), varId(0U), conditional(false), inconclusive(false), defaultArg(false), valueKind(ValueKind::Possible) {}
Value(const Token *c, long long val) : valueType(INT), intvalue(val), tokvalue(nullptr), floatValue(0.0), moveKind(NonMovedVariable), varvalue(val), condition(c), varId(0U), conditional(false), inconclusive(false), defaultArg(false), valueKind(ValueKind::Possible) {
errorPath.push_back(ErrorPathItem(c, "condition"));
}
Value(const Token *c, long long val);
bool operator==(const Value &rhs) const {
if (valueType != rhs.valueType)