Refactoring; enum class

This commit is contained in:
Daniel Marjamäki 2019-07-10 14:04:56 +02:00
parent 1cb90f925e
commit 95d65c8c34
5 changed files with 27 additions and 27 deletions

View File

@ -388,7 +388,7 @@ void CheckType::checkFloatToIntegerOverflow()
continue; continue;
for (const ValueFlow::Value &f : *floatValues) { for (const ValueFlow::Value &f : *floatValues) {
if (f.valueType != ValueFlow::Value::FLOAT) if (f.valueType != ValueFlow::Value::ValueType::FLOAT)
continue; continue;
if (!mSettings->isEnabled(&f, false)) if (!mSettings->isEnabled(&f, false))
continue; continue;

View File

@ -93,7 +93,7 @@ private:
c.longCastAssignError(nullptr); c.longCastAssignError(nullptr);
c.longCastReturnError(nullptr); c.longCastReturnError(nullptr);
ValueFlow::Value f; ValueFlow::Value f;
f.valueType = ValueFlow::Value::FLOAT; f.valueType = ValueFlow::Value::ValueType::FLOAT;
f.floatValue = 1E100; f.floatValue = 1E100;
c.floatToIntegerOverflowError(nullptr, f); c.floatToIntegerOverflowError(nullptr, f);
} }

View File

@ -1292,7 +1292,7 @@ void CheckUninitVar::valueFlowUninit()
if (!tok->variable() || tok->values().size() != 1U) if (!tok->variable() || tok->values().size() != 1U)
continue; continue;
const ValueFlow::Value &v = tok->values().front(); const ValueFlow::Value &v = tok->values().front();
if (v.valueType != ValueFlow::Value::UNINIT || v.isInconclusive()) if (v.valueType != ValueFlow::Value::ValueType::UNINIT || v.isInconclusive())
continue; continue;
if (!isVariableUsage(tok, tok->variable()->isPointer(), NO_ALLOC)) if (!isVariableUsage(tok, tok->variable()->isPointer(), NO_ALLOC))
continue; continue;

View File

@ -369,9 +369,9 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
if (argtok->values().size() != 1U) if (argtok->values().size() != 1U)
continue; continue;
const ValueFlow::Value &v = argtok->values().front(); const ValueFlow::Value &v = argtok->values().front();
if (v.valueType == ValueFlow::Value::UNINIT && !v.isInconclusive()) { if (v.valueType == ValueFlow::Value::ValueType::UNINIT && !v.isInconclusive()) {
FileInfo::FunctionCall functionCall; FileInfo::FunctionCall functionCall;
functionCall.callValueType = ValueFlow::Value::UNINIT; functionCall.callValueType = ValueFlow::Value::ValueType::UNINIT;
functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function()); functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function());
functionCall.callFunctionName = tok->astOperand1()->expressionString(); functionCall.callFunctionName = tok->astOperand1()->expressionString();
functionCall.location.fileName = tokenizer->list.file(tok); functionCall.location.fileName = tokenizer->list.file(tok);
@ -482,15 +482,15 @@ static bool findPath(const std::string &callId,
continue; continue;
switch (invalidValue) { switch (invalidValue) {
case CTU::FileInfo::InvalidValueType::null: case CTU::FileInfo::InvalidValueType::null:
if (functionCall->callValueType != ValueFlow::Value::INT || functionCall->callArgValue != 0) if (functionCall->callValueType != ValueFlow::Value::ValueType::INT || functionCall->callArgValue != 0)
continue; continue;
break; break;
case CTU::FileInfo::InvalidValueType::uninit: case CTU::FileInfo::InvalidValueType::uninit:
if (functionCall->callValueType != ValueFlow::Value::UNINIT) if (functionCall->callValueType != ValueFlow::Value::ValueType::UNINIT)
continue; continue;
break; break;
case CTU::FileInfo::InvalidValueType::bufferOverflow: case CTU::FileInfo::InvalidValueType::bufferOverflow:
if (functionCall->callValueType != ValueFlow::Value::BUFFER_SIZE) if (functionCall->callValueType != ValueFlow::Value::ValueType::BUFFER_SIZE)
continue; continue;
if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue) if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue)
break; break;

View File

@ -41,7 +41,7 @@ namespace ValueFlow {
typedef std::list<ErrorPathItem> ErrorPath; typedef std::list<ErrorPathItem> ErrorPath;
explicit Value(long long val = 0) explicit Value(long long val = 0)
: valueType(INT), : valueType(ValueType::INT),
intvalue(val), intvalue(val),
tokvalue(nullptr), tokvalue(nullptr),
floatValue(0.0), floatValue(0.0),
@ -61,34 +61,34 @@ namespace ValueFlow {
if (valueType != rhs.valueType) if (valueType != rhs.valueType)
return false; return false;
switch (valueType) { switch (valueType) {
case INT: case ValueType::INT:
if (intvalue != rhs.intvalue) if (intvalue != rhs.intvalue)
return false; return false;
break; break;
case TOK: case ValueType::TOK:
if (tokvalue != rhs.tokvalue) if (tokvalue != rhs.tokvalue)
return false; return false;
break; break;
case FLOAT: case ValueType::FLOAT:
// TODO: Write some better comparison // TODO: Write some better comparison
if (floatValue > rhs.floatValue || floatValue < rhs.floatValue) if (floatValue > rhs.floatValue || floatValue < rhs.floatValue)
return false; return false;
break; break;
case MOVED: case ValueType::MOVED:
if (moveKind != rhs.moveKind) if (moveKind != rhs.moveKind)
return false; return false;
break; break;
case UNINIT: case ValueType::UNINIT:
break; break;
case BUFFER_SIZE: case ValueType::BUFFER_SIZE:
if (intvalue != rhs.intvalue) if (intvalue != rhs.intvalue)
return false; return false;
break; break;
case CONTAINER_SIZE: case ValueType::CONTAINER_SIZE:
if (intvalue != rhs.intvalue) if (intvalue != rhs.intvalue)
return false; return false;
break; break;
case LIFETIME: case ValueType::LIFETIME:
if (tokvalue != rhs.tokvalue) if (tokvalue != rhs.tokvalue)
return false; return false;
} }
@ -105,36 +105,36 @@ namespace ValueFlow {
enum ValueType { INT, TOK, FLOAT, MOVED, UNINIT, CONTAINER_SIZE, LIFETIME, BUFFER_SIZE } valueType; enum ValueType { INT, TOK, FLOAT, MOVED, UNINIT, CONTAINER_SIZE, LIFETIME, BUFFER_SIZE } valueType;
bool isIntValue() const { bool isIntValue() const {
return valueType == INT; return valueType == ValueType::INT;
} }
bool isTokValue() const { bool isTokValue() const {
return valueType == TOK; return valueType == ValueType::TOK;
} }
bool isFloatValue() const { bool isFloatValue() const {
return valueType == FLOAT; return valueType == ValueType::FLOAT;
} }
bool isMovedValue() const { bool isMovedValue() const {
return valueType == MOVED; return valueType == ValueType::MOVED;
} }
bool isUninitValue() const { bool isUninitValue() const {
return valueType == UNINIT; return valueType == ValueType::UNINIT;
} }
bool isContainerSizeValue() const { bool isContainerSizeValue() const {
return valueType == CONTAINER_SIZE; return valueType == ValueType::CONTAINER_SIZE;
} }
bool isLifetimeValue() const { bool isLifetimeValue() const {
return valueType == LIFETIME; return valueType == ValueType::LIFETIME;
} }
bool isBufferSizeValue() const { bool isBufferSizeValue() const {
return valueType == BUFFER_SIZE; return valueType == ValueType::BUFFER_SIZE;
} }
bool isLocalLifetimeValue() const { bool isLocalLifetimeValue() const {
return valueType == LIFETIME && lifetimeScope == Local; return valueType == ValueType::LIFETIME && lifetimeScope == Local;
} }
bool isArgumentLifetimeValue() const { bool isArgumentLifetimeValue() const {
return valueType == LIFETIME && lifetimeScope == Argument; return valueType == ValueType::LIFETIME && lifetimeScope == Argument;
} }
/** int value */ /** int value */