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

View File

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

View File

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

View File

@ -458,28 +458,28 @@ private:
" g(std::move(x));\n" " g(std::move(x));\n"
" y=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" code = "void f() {\n"
" X x;\n" " X x;\n"
" g(std::forward<X>(x));\n" " g(std::forward<X>(x));\n"
" y=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" code = "void f() {\n"
" X x;\n" " X x;\n"
" g(std::move(x).getA());\n" // Only parts of x might be moved out " g(std::move(x).getA());\n" // Only parts of x might be moved out
" y=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 = "void f() {\n" code = "void f() {\n"
" X x;\n" " X x;\n"
" g(std::forward<X>(x).getA());\n" // Only parts of x might be moved out " g(std::forward<X>(x).getA());\n" // Only parts of x might be moved out
" y=x;\n" " 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" code = "void f() {\n"
" X x;\n" " X x;\n"
@ -487,7 +487,7 @@ private:
" x.clear();\n" " x.clear();\n"
" y=x;\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" code = "void f() {\n"
" X x;\n" " X x;\n"
@ -495,28 +495,28 @@ private:
" y=x->y;\n" " y=x->y;\n"
" z=x->z;\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" code = "void f(int i) {\n"
" X x;\n" " X x;\n"
" z = g(std::move(x));\n" " z = g(std::move(x));\n"
" y = 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" code = "void f(int i) {\n"
" X x;\n" " X x;\n"
" y = g(std::move(x), \n" " y = g(std::move(x), \n"
" x.size());\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" code = "void f(int i) {\n"
" X x;\n" " X x;\n"
" x = g(std::move(x));\n" " x = g(std::move(x));\n"
" y = 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" code = "A f(int i) {\n"
" X x;\n" " X x;\n"
@ -524,7 +524,7 @@ private:
" return g(std::move(x));\n" " return g(std::move(x));\n"
" return h(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" code = "struct X {\n"
"};\n" "};\n"
@ -538,7 +538,7 @@ private:
" g(std::move(x)).foo([=](int value) mutable {;});\n" " g(std::move(x)).foo([=](int value) mutable {;});\n"
" X y=x;\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() { void valueFlowCalculations() {
@ -2901,7 +2901,7 @@ private:
" g(x);\n" " g(x);\n"
" return 0;\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" code = "class A\n"
"{\n" "{\n"