Refactoring: Use stl algorithm

This commit is contained in:
Daniel Marjamäki 2019-04-28 07:40:00 +02:00
parent 69faa0d8c8
commit fd4e371091
1 changed files with 16 additions and 24 deletions

View File

@ -739,30 +739,22 @@ bool isUniqueExpression(const Token* tok)
// Iterate over the variables in scope and the parameters of the function if possible
const Function * fun = scope->function;
const std::list<Variable>* setOfVars[] = {&scope->varlist, fun ? &fun->argumentList : nullptr};
if (varType) {
for (const std::list<Variable>* vars:setOfVars) {
if (!vars)
continue;
for (const Variable& v:*vars) {
if (v.type() && v.type()->name() == varType->name() && v.name() != var->name()) {
return false;
}
}
}
} else {
for (const std::list<Variable>* vars:setOfVars) {
if (!vars)
continue;
for (const Variable& v:*vars) {
if (v.isFloatingType() == var->isFloatingType() &&
v.isEnumType() == var->isEnumType() &&
v.isClass() == var->isClass() &&
v.isArray() == var->isArray() &&
v.isPointer() == var->isPointer() &&
v.name() != var->name())
return false;
}
}
for (const std::list<Variable>* vars:setOfVars) {
if (!vars)
continue;
bool other = std::any_of(vars->cbegin(), vars->cend(), [=](const Variable &v) {
if (varType)
return v.type() && v.type()->name() == varType->name() && v.name() != var->name();
return v.isFloatingType() == var->isFloatingType() &&
v.isEnumType() == var->isEnumType() &&
v.isClass() == var->isClass() &&
v.isArray() == var->isArray() &&
v.isPointer() == var->isPointer() &&
v.name() != var->name();
});
if (other)
return false;
}
} else if (!isUniqueExpression(tok->astOperand1())) {
return false;