some cleanups (#4308)

This commit is contained in:
Oliver Stöneberg 2022-07-26 08:28:55 +02:00 committed by GitHub
parent 15f8c71ec3
commit 0005be1dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 15 deletions

View File

@ -417,7 +417,6 @@ static std::vector<ValueType> getParentValueTypes(const Token* tok,
if (ftok && argn >= 0) { if (ftok && argn >= 0) {
if (ftok->function()) { if (ftok->function()) {
std::vector<ValueType> result; std::vector<ValueType> result;
std::vector<const Variable*> argsVars = getArgumentVars(ftok, argn);
const Token* nameTok = nullptr; const Token* nameTok = nullptr;
for (const Variable* var : getArgumentVars(ftok, argn)) { for (const Variable* var : getArgumentVars(ftok, argn)) {
if (!var) if (!var)
@ -2064,8 +2063,7 @@ static const std::string& invertAssign(const std::string& assign)
{"^=", "^="}}; {"^=", "^="}};
auto it = lookup.find(assign); auto it = lookup.find(assign);
if (it == lookup.end()) { if (it == lookup.end()) {
static std::string empty; return emptyString;
return empty;
} }
else else
return it->second; return it->second;
@ -4508,7 +4506,6 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
auto captureVariable = [&](const Token* tok2, LifetimeCapture c, std::function<bool(const Token*)> pred) { auto captureVariable = [&](const Token* tok2, LifetimeCapture c, std::function<bool(const Token*)> pred) {
if (varids.count(tok->varId()) > 0) if (varids.count(tok->varId()) > 0)
return; return;
ErrorPath errorPath;
if (c == LifetimeCapture::ByReference) { if (c == LifetimeCapture::ByReference) {
LifetimeStore ls{ LifetimeStore ls{
tok2, "Lambda captures variable by reference here.", ValueFlow::Value::LifetimeKind::Lambda}; tok2, "Lambda captures variable by reference here.", ValueFlow::Value::LifetimeKind::Lambda};
@ -6260,11 +6257,11 @@ struct SimpleConditionHandler : ConditionHandler {
std::vector<Condition> conds; std::vector<Condition> conds;
parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) { parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
Condition cond;
if (vartok->hasKnownIntValue()) if (vartok->hasKnownIntValue())
return; return;
if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2()) if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2())
vartok = vartok->astOperand1(); vartok = vartok->astOperand1();
Condition cond;
cond.true_values.push_back(true_value); cond.true_values.push_back(true_value);
cond.false_values.push_back(false_value); cond.false_values.push_back(false_value);
cond.vartok = vartok; cond.vartok = vartok;
@ -6273,9 +6270,6 @@ struct SimpleConditionHandler : ConditionHandler {
if (!conds.empty()) if (!conds.empty())
return conds; return conds;
Condition cond;
ValueFlow::Value true_value;
ValueFlow::Value false_value;
const Token* vartok = nullptr; const Token* vartok = nullptr;
if (tok->str() == "!") { if (tok->str() == "!") {
@ -6291,6 +6285,7 @@ struct SimpleConditionHandler : ConditionHandler {
if (!vartok) if (!vartok)
return {}; return {};
Condition cond;
cond.true_values.emplace_back(tok, 0LL); cond.true_values.emplace_back(tok, 0LL);
cond.false_values.emplace_back(tok, 0LL); cond.false_values.emplace_back(tok, 0LL);
cond.vartok = vartok; cond.vartok = vartok;
@ -7682,7 +7677,6 @@ bool isContainerSizeChanged(const Token* tok, const Settings* settings, int dept
if (astIsLHS(tok) && Token::simpleMatch(tok->astParent(), "[")) if (astIsLHS(tok) && Token::simpleMatch(tok->astParent(), "["))
return container->stdAssociativeLike; return container->stdAssociativeLike;
Library::Container::Action action = astContainerAction(tok); Library::Container::Action action = astContainerAction(tok);
Library::Container::Yield yield = astContainerYield(tok);
switch (action) { switch (action) {
case Library::Container::Action::RESIZE: case Library::Container::Action::RESIZE:
case Library::Container::Action::CLEAR: case Library::Container::Action::CLEAR:
@ -7694,8 +7688,10 @@ bool isContainerSizeChanged(const Token* tok, const Settings* settings, int dept
return true; return true;
case Library::Container::Action::NO_ACTION: case Library::Container::Action::NO_ACTION:
// Is this an unknown member function call? // Is this an unknown member function call?
if (astIsLHS(tok) && Token::Match(tok->astParent(), ". %name% (")) if (astIsLHS(tok) && Token::Match(tok->astParent(), ". %name% (")) {
Library::Container::Yield yield = astContainerYield(tok);
return yield == Library::Container::Yield::NO_YIELD; return yield == Library::Container::Yield::NO_YIELD;
}
break; break;
case Library::Container::Action::FIND: case Library::Container::Action::FIND:
case Library::Container::Action::CHANGE_CONTENT: case Library::Container::Action::CHANGE_CONTENT:
@ -7842,9 +7838,6 @@ struct IteratorConditionHandler : SimpleConditionHandler {
std::vector<Condition> parse(const Token* tok, const Settings*) const override { std::vector<Condition> parse(const Token* tok, const Settings*) const override {
Condition cond; Condition cond;
ValueFlow::Value true_value;
ValueFlow::Value false_value;
if (Token::Match(tok, "==|!=")) { if (Token::Match(tok, "==|!=")) {
if (!tok->astOperand1() || !tok->astOperand2()) if (!tok->astOperand1() || !tok->astOperand2())
return {}; return {};
@ -8141,12 +8134,12 @@ struct ContainerConditionHandler : ConditionHandler {
{ {
std::vector<Condition> conds; std::vector<Condition> conds;
parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) { parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
Condition cond;
vartok = settings->library.getContainerFromYield(vartok, Library::Container::Yield::SIZE); vartok = settings->library.getContainerFromYield(vartok, Library::Container::Yield::SIZE);
if (!vartok) if (!vartok)
return; return;
true_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; true_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
false_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; false_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
Condition cond;
cond.true_values.push_back(true_value); cond.true_values.push_back(true_value);
cond.false_values.push_back(false_value); cond.false_values.push_back(false_value);
cond.vartok = vartok; cond.vartok = vartok;
@ -8155,7 +8148,6 @@ struct ContainerConditionHandler : ConditionHandler {
if (!conds.empty()) if (!conds.empty())
return conds; return conds;
Condition cond;
const Token* vartok = nullptr; const Token* vartok = nullptr;
// Empty check // Empty check
@ -8172,6 +8164,7 @@ struct ContainerConditionHandler : ConditionHandler {
} }
ValueFlow::Value value(tok, 0LL); ValueFlow::Value value(tok, 0LL);
value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
Condition cond;
cond.true_values.emplace_back(value); cond.true_values.emplace_back(value);
cond.false_values.emplace_back(std::move(value)); cond.false_values.emplace_back(std::move(value));
cond.vartok = vartok; cond.vartok = vartok;
@ -8194,6 +8187,7 @@ struct ContainerConditionHandler : ConditionHandler {
return {}; return {};
ValueFlow::Value value(tok, Token::getStrLength(strtok)); ValueFlow::Value value(tok, Token::getStrLength(strtok));
value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
Condition cond;
cond.false_values.emplace_back(value); cond.false_values.emplace_back(value);
cond.true_values.emplace_back(std::move(value)); cond.true_values.emplace_back(std::move(value));
cond.vartok = vartok; cond.vartok = vartok;