From 95d65c8c34ff8a6d27a777e32e443e4d1f3caca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 10 Jul 2019 14:04:56 +0200 Subject: [PATCH] Refactoring; enum class --- lib/checktype.cpp | 2 +- lib/checktype.h | 2 +- lib/checkuninitvar.cpp | 2 +- lib/ctu.cpp | 10 +++++----- lib/valueflow.h | 38 +++++++++++++++++++------------------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 929bb9eeb..3421dc286 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -388,7 +388,7 @@ void CheckType::checkFloatToIntegerOverflow() continue; for (const ValueFlow::Value &f : *floatValues) { - if (f.valueType != ValueFlow::Value::FLOAT) + if (f.valueType != ValueFlow::Value::ValueType::FLOAT) continue; if (!mSettings->isEnabled(&f, false)) continue; diff --git a/lib/checktype.h b/lib/checktype.h index 3776a5961..b786287b8 100644 --- a/lib/checktype.h +++ b/lib/checktype.h @@ -93,7 +93,7 @@ private: c.longCastAssignError(nullptr); c.longCastReturnError(nullptr); ValueFlow::Value f; - f.valueType = ValueFlow::Value::FLOAT; + f.valueType = ValueFlow::Value::ValueType::FLOAT; f.floatValue = 1E100; c.floatToIntegerOverflowError(nullptr, f); } diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 961103b7f..0d09286a9 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1292,7 +1292,7 @@ void CheckUninitVar::valueFlowUninit() if (!tok->variable() || tok->values().size() != 1U) continue; 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; if (!isVariableUsage(tok, tok->variable()->isPointer(), NO_ALLOC)) continue; diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 7055bf130..545b9ff75 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -369,9 +369,9 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer) if (argtok->values().size() != 1U) continue; 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; - functionCall.callValueType = ValueFlow::Value::UNINIT; + functionCall.callValueType = ValueFlow::Value::ValueType::UNINIT; functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function()); functionCall.callFunctionName = tok->astOperand1()->expressionString(); functionCall.location.fileName = tokenizer->list.file(tok); @@ -482,15 +482,15 @@ static bool findPath(const std::string &callId, continue; switch (invalidValue) { 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; break; case CTU::FileInfo::InvalidValueType::uninit: - if (functionCall->callValueType != ValueFlow::Value::UNINIT) + if (functionCall->callValueType != ValueFlow::Value::ValueType::UNINIT) continue; break; case CTU::FileInfo::InvalidValueType::bufferOverflow: - if (functionCall->callValueType != ValueFlow::Value::BUFFER_SIZE) + if (functionCall->callValueType != ValueFlow::Value::ValueType::BUFFER_SIZE) continue; if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue) break; diff --git a/lib/valueflow.h b/lib/valueflow.h index 93b040ca8..0df790856 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -41,7 +41,7 @@ namespace ValueFlow { typedef std::list ErrorPath; explicit Value(long long val = 0) - : valueType(INT), + : valueType(ValueType::INT), intvalue(val), tokvalue(nullptr), floatValue(0.0), @@ -61,34 +61,34 @@ namespace ValueFlow { if (valueType != rhs.valueType) return false; switch (valueType) { - case INT: + case ValueType::INT: if (intvalue != rhs.intvalue) return false; break; - case TOK: + case ValueType::TOK: if (tokvalue != rhs.tokvalue) return false; break; - case FLOAT: + case ValueType::FLOAT: // TODO: Write some better comparison if (floatValue > rhs.floatValue || floatValue < rhs.floatValue) return false; break; - case MOVED: + case ValueType::MOVED: if (moveKind != rhs.moveKind) return false; break; - case UNINIT: + case ValueType::UNINIT: break; - case BUFFER_SIZE: + case ValueType::BUFFER_SIZE: if (intvalue != rhs.intvalue) return false; break; - case CONTAINER_SIZE: + case ValueType::CONTAINER_SIZE: if (intvalue != rhs.intvalue) return false; break; - case LIFETIME: + case ValueType::LIFETIME: if (tokvalue != rhs.tokvalue) return false; } @@ -105,36 +105,36 @@ namespace ValueFlow { enum ValueType { INT, TOK, FLOAT, MOVED, UNINIT, CONTAINER_SIZE, LIFETIME, BUFFER_SIZE } valueType; bool isIntValue() const { - return valueType == INT; + return valueType == ValueType::INT; } bool isTokValue() const { - return valueType == TOK; + return valueType == ValueType::TOK; } bool isFloatValue() const { - return valueType == FLOAT; + return valueType == ValueType::FLOAT; } bool isMovedValue() const { - return valueType == MOVED; + return valueType == ValueType::MOVED; } bool isUninitValue() const { - return valueType == UNINIT; + return valueType == ValueType::UNINIT; } bool isContainerSizeValue() const { - return valueType == CONTAINER_SIZE; + return valueType == ValueType::CONTAINER_SIZE; } bool isLifetimeValue() const { - return valueType == LIFETIME; + return valueType == ValueType::LIFETIME; } bool isBufferSizeValue() const { - return valueType == BUFFER_SIZE; + return valueType == ValueType::BUFFER_SIZE; } bool isLocalLifetimeValue() const { - return valueType == LIFETIME && lifetimeScope == Local; + return valueType == ValueType::LIFETIME && lifetimeScope == Local; } bool isArgumentLifetimeValue() const { - return valueType == LIFETIME && lifetimeScope == Argument; + return valueType == ValueType::LIFETIME && lifetimeScope == Argument; } /** int value */