Refactoring: enum class

This commit is contained in:
Daniel Marjamäki 2019-07-10 15:27:07 +02:00
parent 95d65c8c34
commit 9f548efbd3
5 changed files with 29 additions and 29 deletions

View File

@ -2583,7 +2583,7 @@ void CheckOther::checkAccessOfMovedVariable()
}
for (const Token* tok = scopeStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
const ValueFlow::Value * movedValue = tok->getMovedValue();
if (!movedValue || movedValue->moveKind == ValueFlow::Value::NonMovedVariable)
if (!movedValue || movedValue->moveKind == ValueFlow::Value::MoveKind::NonMovedVariable)
continue;
if (movedValue->isInconclusive() && !reportInconclusive)
continue;
@ -2634,11 +2634,11 @@ void CheckOther::accessMovedError(const Token *tok, const std::string &varname,
const char * errorId = nullptr;
std::string kindString;
switch (value->moveKind) {
case ValueFlow::Value::MovedVariable:
case ValueFlow::Value::MoveKind::MovedVariable:
errorId = "accessMoved";
kindString = "moved";
break;
case ValueFlow::Value::ForwardedVariable:
case ValueFlow::Value::MoveKind::ForwardedVariable:
errorId = "accessForwarded";
kindString = "forwarded";
break;

View File

@ -955,7 +955,7 @@ public:
if (!mImpl->mValues)
return nullptr;
const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [](const ValueFlow::Value &value) {
return value.isMovedValue() && value.moveKind != ValueFlow::Value::NonMovedVariable;
return value.isMovedValue() && value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable;
});
return it == mImpl->mValues->end() ? nullptr : &*it;;
}

View File

@ -3400,17 +3400,17 @@ static bool isStdMoveOrStdForwarded(Token * tok, ValueFlow::Value::MoveKind * mo
{
if (tok->str() != "std")
return false;
ValueFlow::Value::MoveKind kind = ValueFlow::Value::NonMovedVariable;
ValueFlow::Value::MoveKind kind = ValueFlow::Value::MoveKind::NonMovedVariable;
Token * variableToken = nullptr;
if (Token::Match(tok, "std :: move ( %var% )")) {
variableToken = tok->tokAt(4);
kind = ValueFlow::Value::MovedVariable;
kind = ValueFlow::Value::MoveKind::MovedVariable;
} else if (Token::simpleMatch(tok, "std :: forward <")) {
const Token * const leftAngle = tok->tokAt(3);
Token * rightAngle = leftAngle->link();
if (Token::Match(rightAngle, "> ( %var% )")) {
variableToken = rightAngle->tokAt(2);
kind = ValueFlow::Value::ForwardedVariable;
kind = ValueFlow::Value::MoveKind::ForwardedVariable;
}
}
if (!variableToken)
@ -3471,8 +3471,8 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab
if (Token::Match(tok, "%var% . reset|clear (") && tok->next()->originalName() == emptyString) {
varTok = tok;
ValueFlow::Value value;
value.valueType = ValueFlow::Value::MOVED;
value.moveKind = ValueFlow::Value::NonMovedVariable;
value.valueType = ValueFlow::Value::ValueType::MOVED;
value.moveKind = ValueFlow::Value::MoveKind::NonMovedVariable;
value.errorPath.emplace_back(tok, "Calling " + tok->next()->expressionString() + " makes " + tok->str() + " 'non-moved'");
value.setKnown();
std::list<ValueFlow::Value> values;
@ -3508,9 +3508,9 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab
const Token * const endOfVarScope = var->typeStartToken()->scope()->bodyEnd;
ValueFlow::Value value;
value.valueType = ValueFlow::Value::MOVED;
value.valueType = ValueFlow::Value::ValueType::MOVED;
value.moveKind = moveKind;
if (moveKind == ValueFlow::Value::MovedVariable)
if (moveKind == ValueFlow::Value::MoveKind::MovedVariable)
value.errorPath.emplace_back(tok, "Calling std::move(" + varTok->str() + ")");
else // if (moveKind == ValueFlow::Value::ForwardedVariable)
value.errorPath.emplace_back(tok, "Calling std::forward(" + varTok->str() + ")");
@ -5343,7 +5343,7 @@ ValueFlow::Value::Value(const Token *c, long long val)
intvalue(val),
tokvalue(nullptr),
floatValue(0.0),
moveKind(NonMovedVariable),
moveKind(MoveKind::NonMovedVariable),
varvalue(val),
condition(c),
varId(0U),

View File

@ -45,7 +45,7 @@ namespace ValueFlow {
intvalue(val),
tokvalue(nullptr),
floatValue(0.0),
moveKind(NonMovedVariable),
moveKind(MoveKind::NonMovedVariable),
varvalue(val),
condition(nullptr),
varId(0U),
@ -147,7 +147,7 @@ namespace ValueFlow {
double floatValue;
/** kind of moved */
enum MoveKind {NonMovedVariable, MovedVariable, ForwardedVariable} moveKind;
enum class MoveKind {NonMovedVariable, MovedVariable, ForwardedVariable} moveKind;
/** For calculated values - variable value that calculated value depends on */
long long varvalue;
@ -172,11 +172,11 @@ namespace ValueFlow {
static const char * toString(MoveKind moveKind) {
switch (moveKind) {
case NonMovedVariable:
case MoveKind::NonMovedVariable:
return "NonMovedVariable";
case MovedVariable:
case MoveKind::MovedVariable:
return "MovedVariable";
case ForwardedVariable:
case MoveKind::ForwardedVariable:
return "ForwardedVariable";
}
return "";

View File

@ -458,28 +458,28 @@ private:
" g(std::move(x));\n"
" y=x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
code = "void f() {\n"
" X x;\n"
" g(std::forward<X>(x));\n"
" y=x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::ForwardedVariable));
ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::ForwardedVariable));
code = "void f() {\n"
" X x;\n"
" g(std::move(x).getA());\n" // Only parts of x might be moved out
" y=x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
code = "void f() {\n"
" X x;\n"
" g(std::forward<X>(x).getA());\n" // Only parts of x might be moved out
" y=x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::ForwardedVariable));
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::ForwardedVariable));
code = "void f() {\n"
" X x;\n"
@ -487,7 +487,7 @@ private:
" x.clear();\n"
" y=x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable));
code = "void f() {\n"
" X x;\n"
@ -495,28 +495,28 @@ private:
" y=x->y;\n"
" z=x->z;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(true, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable));
code = "void f(int i) {\n"
" X x;\n"
" z = g(std::move(x));\n"
" y = x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
code = "void f(int i) {\n"
" X x;\n"
" y = g(std::move(x), \n"
" x.size());\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
code = "void f(int i) {\n"
" X x;\n"
" x = g(std::move(x));\n"
" y = x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
code = "A f(int i) {\n"
" X x;\n"
@ -524,7 +524,7 @@ private:
" return g(std::move(x));\n"
" return h(std::move(x));\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable));
code = "struct X {\n"
"};\n"
@ -538,7 +538,7 @@ private:
" g(std::move(x)).foo([=](int value) mutable {;});\n"
" X y=x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 11U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(true, testValueOfX(code, 11U, ValueFlow::Value::MoveKind::MovedVariable));
}
void valueFlowCalculations() {
@ -2901,7 +2901,7 @@ private:
" g(x);\n"
" return 0;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable));
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
code = "class A\n"
"{\n"