Refactoring: Use enum class
This commit is contained in:
parent
4e89b13adf
commit
32eda27391
|
@ -643,17 +643,17 @@ static std::string lifetimeMessage(const Token *tok, const ValueFlow::Value *val
|
||||||
const Variable * var = vartok->variable();
|
const Variable * var = vartok->variable();
|
||||||
if (var) {
|
if (var) {
|
||||||
switch (val->lifetimeKind) {
|
switch (val->lifetimeKind) {
|
||||||
case ValueFlow::Value::Object:
|
case ValueFlow::Value::LifetimeKind::Object:
|
||||||
case ValueFlow::Value::Address:
|
case ValueFlow::Value::LifetimeKind::Address:
|
||||||
if (type == "pointer")
|
if (type == "pointer")
|
||||||
msg += " to local variable";
|
msg += " to local variable";
|
||||||
else
|
else
|
||||||
msg += " that points to local variable";
|
msg += " that points to local variable";
|
||||||
break;
|
break;
|
||||||
case ValueFlow::Value::Lambda:
|
case ValueFlow::Value::LifetimeKind::Lambda:
|
||||||
msg += " that captures local variable";
|
msg += " that captures local variable";
|
||||||
break;
|
break;
|
||||||
case ValueFlow::Value::Iterator:
|
case ValueFlow::Value::LifetimeKind::Iterator:
|
||||||
msg += " to local container";
|
msg += " to local container";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -894,7 +894,7 @@ void CheckBufferOverrun::objectIndex()
|
||||||
ValueFlow::Value v = getLifetimeObjValue(obj);
|
ValueFlow::Value v = getLifetimeObjValue(obj);
|
||||||
if (!v.isLocalLifetimeValue())
|
if (!v.isLocalLifetimeValue())
|
||||||
continue;
|
continue;
|
||||||
if (v.lifetimeKind != ValueFlow::Value::Address)
|
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
|
||||||
continue;
|
continue;
|
||||||
const Variable *var = v.tokvalue->variable();
|
const Variable *var = v.tokvalue->variable();
|
||||||
if (var->isReference())
|
if (var->isReference())
|
||||||
|
|
|
@ -449,7 +449,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.isLifetimeValue()) {
|
if (value.isLifetimeValue()) {
|
||||||
if (value.lifetimeKind == ValueFlow::Value::Iterator && astIsIterator(parent)) {
|
if (value.lifetimeKind == ValueFlow::Value::LifetimeKind::Iterator && astIsIterator(parent)) {
|
||||||
setTokenValue(parent,value,settings);
|
setTokenValue(parent,value,settings);
|
||||||
} else if (astIsPointer(tok) && astIsPointer(parent) &&
|
} else if (astIsPointer(tok) && astIsPointer(parent) &&
|
||||||
(parent->isArithmeticalOp() || Token::Match(parent, "( %type%"))) {
|
(parent->isArithmeticalOp() || Token::Match(parent, "( %type%"))) {
|
||||||
|
@ -2689,14 +2689,14 @@ std::string lifetimeType(const Token *tok, const ValueFlow::Value *val)
|
||||||
if (!val)
|
if (!val)
|
||||||
return "object";
|
return "object";
|
||||||
switch (val->lifetimeKind) {
|
switch (val->lifetimeKind) {
|
||||||
case ValueFlow::Value::Lambda:
|
case ValueFlow::Value::LifetimeKind::Lambda:
|
||||||
result = "lambda";
|
result = "lambda";
|
||||||
break;
|
break;
|
||||||
case ValueFlow::Value::Iterator:
|
case ValueFlow::Value::LifetimeKind::Iterator:
|
||||||
result = "iterator";
|
result = "iterator";
|
||||||
break;
|
break;
|
||||||
case ValueFlow::Value::Object:
|
case ValueFlow::Value::LifetimeKind::Object:
|
||||||
case ValueFlow::Value::Address:
|
case ValueFlow::Value::LifetimeKind::Address:
|
||||||
if (astIsPointer(tok))
|
if (astIsPointer(tok))
|
||||||
result = "pointer";
|
result = "pointer";
|
||||||
else
|
else
|
||||||
|
@ -3003,7 +3003,7 @@ struct LifetimeStore {
|
||||||
|
|
||||||
LifetimeStore(const Token *argtok,
|
LifetimeStore(const Token *argtok,
|
||||||
const std::string &message,
|
const std::string &message,
|
||||||
ValueFlow::Value::LifetimeKind type = ValueFlow::Value::Object)
|
ValueFlow::Value::LifetimeKind type = ValueFlow::Value::LifetimeKind::Object)
|
||||||
: argtok(argtok), message(message), type(type), errorPath()
|
: argtok(argtok), message(message), type(type), errorPath()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -3122,12 +3122,12 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog
|
||||||
return;
|
return;
|
||||||
if (Token::Match(tok->tokAt(-2), "std :: ref|cref|tie|front_inserter|back_inserter")) {
|
if (Token::Match(tok->tokAt(-2), "std :: ref|cref|tie|front_inserter|back_inserter")) {
|
||||||
for (const Token *argtok : getArguments(tok)) {
|
for (const Token *argtok : getArguments(tok)) {
|
||||||
LifetimeStore{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::Object} .byRef(
|
LifetimeStore{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Object} .byRef(
|
||||||
tok->next(), tokenlist, errorLogger, settings);
|
tok->next(), tokenlist, errorLogger, settings);
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok->tokAt(-2), "std :: make_tuple|tuple_cat|make_pair|make_reverse_iterator|next|prev|move")) {
|
} else if (Token::Match(tok->tokAt(-2), "std :: make_tuple|tuple_cat|make_pair|make_reverse_iterator|next|prev|move")) {
|
||||||
for (const Token *argtok : getArguments(tok)) {
|
for (const Token *argtok : getArguments(tok)) {
|
||||||
LifetimeStore{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::Object} .byVal(
|
LifetimeStore{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Object} .byVal(
|
||||||
tok->next(), tokenlist, errorLogger, settings);
|
tok->next(), tokenlist, errorLogger, settings);
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok->tokAt(-2), "%var% . push_back|push_front|insert|push|assign") &&
|
} else if (Token::Match(tok->tokAt(-2), "%var% . push_back|push_front|insert|push|assign") &&
|
||||||
|
@ -3138,10 +3138,10 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog
|
||||||
if (n > 1 && Token::typeStr(args[n - 2]) == Token::typeStr(args[n - 1]) &&
|
if (n > 1 && Token::typeStr(args[n - 2]) == Token::typeStr(args[n - 1]) &&
|
||||||
(((astIsIterator(args[n - 2]) && astIsIterator(args[n - 1])) ||
|
(((astIsIterator(args[n - 2]) && astIsIterator(args[n - 1])) ||
|
||||||
(astIsPointer(args[n - 2]) && astIsPointer(args[n - 1]))))) {
|
(astIsPointer(args[n - 2]) && astIsPointer(args[n - 1]))))) {
|
||||||
LifetimeStore{args.back(), "Added to container '" + vartok->str() + "'.", ValueFlow::Value::Object} .byDerefCopy(
|
LifetimeStore{args.back(), "Added to container '" + vartok->str() + "'.", ValueFlow::Value::LifetimeKind::Object} .byDerefCopy(
|
||||||
vartok, tokenlist, errorLogger, settings);
|
vartok, tokenlist, errorLogger, settings);
|
||||||
} else if (!args.empty() && isLifetimeBorrowed(args.back(), settings)) {
|
} else if (!args.empty() && isLifetimeBorrowed(args.back(), settings)) {
|
||||||
LifetimeStore{args.back(), "Added to container '" + vartok->str() + "'.", ValueFlow::Value::Object} .byVal(
|
LifetimeStore{args.back(), "Added to container '" + vartok->str() + "'.", ValueFlow::Value::LifetimeKind::Object} .byVal(
|
||||||
vartok, tokenlist, errorLogger, settings);
|
vartok, tokenlist, errorLogger, settings);
|
||||||
}
|
}
|
||||||
} else if (tok->function()) {
|
} else if (tok->function()) {
|
||||||
|
@ -3176,7 +3176,7 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const Token *argtok = args[n];
|
const Token *argtok = args[n];
|
||||||
LifetimeStore ls{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::Object};
|
LifetimeStore ls{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Object};
|
||||||
ls.errorPath = v.errorPath;
|
ls.errorPath = v.errorPath;
|
||||||
ls.errorPath.emplace_front(returnTok, "Return " + lifetimeType(returnTok, &v) + ".");
|
ls.errorPath.emplace_front(returnTok, "Return " + lifetimeType(returnTok, &v) + ".");
|
||||||
if (var->isReference() || var->isRValueReference()) {
|
if (var->isReference() || var->isRValueReference()) {
|
||||||
|
@ -3204,7 +3204,7 @@ static void valueFlowLifetimeConstructor(Token *tok, TokenList *tokenlist, Error
|
||||||
if (i >= args.size())
|
if (i >= args.size())
|
||||||
break;
|
break;
|
||||||
const Token *argtok = args[i];
|
const Token *argtok = args[i];
|
||||||
LifetimeStore ls{argtok, "Passed to constructor of '" + t->name() + "'.", ValueFlow::Value::Object};
|
LifetimeStore ls{argtok, "Passed to constructor of '" + t->name() + "'.", ValueFlow::Value::LifetimeKind::Object};
|
||||||
if (var.isReference() || var.isRValueReference()) {
|
if (var.isReference() || var.isRValueReference()) {
|
||||||
ls.byRef(tok, tokenlist, errorLogger, settings);
|
ls.byRef(tok, tokenlist, errorLogger, settings);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3216,7 +3216,7 @@ static void valueFlowLifetimeConstructor(Token *tok, TokenList *tokenlist, Error
|
||||||
} else if (Token::simpleMatch(tok, "{") && (astIsContainer(tok->astParent()) || astIsPointer(tok->astParent()))) {
|
} else if (Token::simpleMatch(tok, "{") && (astIsContainer(tok->astParent()) || astIsPointer(tok->astParent()))) {
|
||||||
std::vector<const Token *> args = getArguments(tok);
|
std::vector<const Token *> args = getArguments(tok);
|
||||||
for (const Token *argtok : args) {
|
for (const Token *argtok : args) {
|
||||||
LifetimeStore ls{argtok, "Passed to initializer list.", ValueFlow::Value::Object};
|
LifetimeStore ls{argtok, "Passed to initializer list.", ValueFlow::Value::LifetimeKind::Object};
|
||||||
ls.byVal(tok, tokenlist, errorLogger, settings);
|
ls.byVal(tok, tokenlist, errorLogger, settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3310,10 +3310,10 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
for (const Token * tok2 = lam.bodyTok; tok2 != lam.bodyTok->link(); tok2 = tok2->next()) {
|
for (const Token * tok2 = lam.bodyTok; tok2 != lam.bodyTok->link(); tok2 = tok2->next()) {
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
if (captureByRef) {
|
if (captureByRef) {
|
||||||
LifetimeStore{tok2, "Lambda captures variable by reference here.", ValueFlow::Value::Lambda} .byRef(
|
LifetimeStore{tok2, "Lambda captures variable by reference here.", ValueFlow::Value::LifetimeKind::Lambda} .byRef(
|
||||||
tok, tokenlist, errorLogger, settings, isCapturingVariable);
|
tok, tokenlist, errorLogger, settings, isCapturingVariable);
|
||||||
} else if (captureByValue) {
|
} else if (captureByValue) {
|
||||||
LifetimeStore{tok2, "Lambda captures variable by value here.", ValueFlow::Value::Lambda} .byVal(
|
LifetimeStore{tok2, "Lambda captures variable by value here.", ValueFlow::Value::LifetimeKind::Lambda} .byVal(
|
||||||
tok, tokenlist, errorLogger, settings, isCapturingVariable);
|
tok, tokenlist, errorLogger, settings, isCapturingVariable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3333,7 +3333,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
value.tokvalue = lifeTok;
|
value.tokvalue = lifeTok;
|
||||||
value.errorPath = errorPath;
|
value.errorPath = errorPath;
|
||||||
if (astIsPointer(lifeTok) || !Token::Match(lifeTok->astParent(), ".|["))
|
if (astIsPointer(lifeTok) || !Token::Match(lifeTok->astParent(), ".|["))
|
||||||
value.lifetimeKind = ValueFlow::Value::Address;
|
value.lifetimeKind = ValueFlow::Value::LifetimeKind::Address;
|
||||||
setTokenValue(tok, value, tokenlist->getSettings());
|
setTokenValue(tok, value, tokenlist->getSettings());
|
||||||
|
|
||||||
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
|
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
|
||||||
|
@ -3358,7 +3358,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
value.lifetimeScope = ValueFlow::Value::Local;
|
value.lifetimeScope = ValueFlow::Value::Local;
|
||||||
value.tokvalue = tok;
|
value.tokvalue = tok;
|
||||||
value.errorPath = errorPath;
|
value.errorPath = errorPath;
|
||||||
value.lifetimeKind = isIterator ? ValueFlow::Value::Iterator : ValueFlow::Value::Object;
|
value.lifetimeKind = isIterator ? ValueFlow::Value::LifetimeKind::Iterator : ValueFlow::Value::LifetimeKind::Object;
|
||||||
setTokenValue(tok->tokAt(3), value, tokenlist->getSettings());
|
setTokenValue(tok->tokAt(3), value, tokenlist->getSettings());
|
||||||
|
|
||||||
valueFlowForwardLifetime(tok->tokAt(3), tokenlist, errorLogger, settings);
|
valueFlowForwardLifetime(tok->tokAt(3), tokenlist, errorLogger, settings);
|
||||||
|
@ -5501,7 +5501,7 @@ ValueFlow::Value::Value(const Token *c, long long val)
|
||||||
varId(0U),
|
varId(0U),
|
||||||
conditional(false),
|
conditional(false),
|
||||||
defaultArg(false),
|
defaultArg(false),
|
||||||
lifetimeKind(Object),
|
lifetimeKind(LifetimeKind::Object),
|
||||||
lifetimeScope(Local),
|
lifetimeScope(Local),
|
||||||
valueKind(ValueKind::Possible)
|
valueKind(ValueKind::Possible)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace ValueFlow {
|
||||||
varId(0U),
|
varId(0U),
|
||||||
conditional(false),
|
conditional(false),
|
||||||
defaultArg(false),
|
defaultArg(false),
|
||||||
lifetimeKind(Object),
|
lifetimeKind(LifetimeKind::Object),
|
||||||
lifetimeScope(Local),
|
lifetimeScope(Local),
|
||||||
valueKind(ValueKind::Possible)
|
valueKind(ValueKind::Possible)
|
||||||
{}
|
{}
|
||||||
|
@ -167,7 +167,7 @@ namespace ValueFlow {
|
||||||
/** Is this value passed as default parameter to the function? */
|
/** Is this value passed as default parameter to the function? */
|
||||||
bool defaultArg;
|
bool defaultArg;
|
||||||
|
|
||||||
enum LifetimeKind {Object, Lambda, Iterator, Address} lifetimeKind;
|
enum class LifetimeKind {Object, Lambda, Iterator, Address} lifetimeKind;
|
||||||
|
|
||||||
enum LifetimeScope { Local, Argument } lifetimeScope;
|
enum LifetimeScope { Local, Argument } lifetimeScope;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue