Refactoring; Use range for loop

This commit is contained in:
Daniel Marjamäki 2018-07-14 08:18:10 +02:00
parent 5b1d96b346
commit c60763bc14
1 changed files with 22 additions and 36 deletions

View File

@ -311,8 +311,7 @@ void CheckCondition::comparison()
continue;
std::list<MathLib::bigint> numbers;
getnumchildren(expr1, numbers);
for (std::list<MathLib::bigint>::const_iterator num = numbers.begin(); num != numbers.end(); ++num) {
const MathLib::bigint num1 = *num;
for (const MathLib::bigint num1 : numbers) {
if (num1 < 0)
continue;
if (Token::Match(tok, "==|!=")) {
@ -412,13 +411,13 @@ void CheckCondition::multiCondition()
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
if (i->type != Scope::eIf)
for (const Scope &scope : symbolDatabase->scopeList) {
if (scope.type != Scope::eIf)
continue;
const Token * const cond1 = i->classDef->next()->astOperand2();
const Token * const cond1 = scope.classDef->next()->astOperand2();
const Token * tok2 = i->classDef->next();
const Token * tok2 = scope.classDef->next();
for (;;) {
tok2 = tok2->link();
if (!Token::simpleMatch(tok2, ") {"))
@ -472,12 +471,12 @@ void CheckCondition::multiCondition2()
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
for (const Scope &scope : symbolDatabase->scopeList) {
const Token *condTok = nullptr;
if (scope->type == Scope::eIf || scope->type == Scope::eWhile)
condTok = scope->classDef->next()->astOperand2();
else if (scope->type == Scope::eFor) {
condTok = scope->classDef->next()->astOperand2();
if (scope.type == Scope::eIf || scope.type == Scope::eWhile)
condTok = scope.classDef->next()->astOperand2();
else if (scope.type == Scope::eFor) {
condTok = scope.classDef->next()->astOperand2();
if (!condTok || condTok->str() != ";")
continue;
condTok = condTok->astOperand2();
@ -489,7 +488,7 @@ void CheckCondition::multiCondition2()
continue;
const Token * const cond1 = condTok;
if (!Token::simpleMatch(scope->classDef->linkAt(1), ") {"))
if (!Token::simpleMatch(scope.classDef->linkAt(1), ") {"))
continue;
bool nonConstFunctionCall = false;
@ -534,11 +533,11 @@ void CheckCondition::multiCondition2()
// parse until second condition is reached..
enum MULTICONDITIONTYPE { INNER, AFTER } type;
const Token *tok;
if (Token::Match(scope->bodyStart, "{ return|throw|continue|break")) {
tok = scope->bodyEnd->next();
if (Token::Match(scope.bodyStart, "{ return|throw|continue|break")) {
tok = scope.bodyEnd->next();
type = MULTICONDITIONTYPE::AFTER;
} else {
tok = scope->bodyStart;
tok = scope.bodyStart;
type = MULTICONDITIONTYPE::INNER;
}
const Token * const endToken = tok->scope()->bodyEnd;
@ -628,8 +627,8 @@ void CheckCondition::multiCondition2()
break;
}
bool changed = false;
for (std::set<unsigned int>::const_iterator it = vars.begin(); it != vars.end(); ++it) {
if (isVariableChanged(tok1, tok2, *it, nonlocal, mSettings, mTokenizer->isCPP())) {
for (unsigned int varid : vars) {
if (isVariableChanged(tok1, tok2, varid, nonlocal, mSettings, mTokenizer->isCPP())) {
changed = true;
break;
}
@ -871,9 +870,7 @@ void CheckCondition::checkIncorrectLogicOperator()
const bool printInconclusive = mSettings->inconclusive;
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t ii = 0; ii < functions; ++ii) {
const Scope * scope = symbolDatabase->functionScopes[ii];
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (!Token::Match(tok, "%oror%|&&") || !tok->astOperand1() || !tok->astOperand2())
@ -1063,9 +1060,7 @@ void CheckCondition::checkModuloAlwaysTrueFalse()
return;
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (!tok->isComparisonOp())
continue;
@ -1119,9 +1114,7 @@ void CheckCondition::clarifyCondition()
const bool isC = mTokenizer->isC();
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (Token::Match(tok, "( %name% [=&|^]")) {
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
@ -1184,10 +1177,7 @@ void CheckCondition::alwaysTrueFalse()
return;
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (tok->link()) // don't write false positives when templates are used
@ -1297,9 +1287,7 @@ void CheckCondition::checkInvalidTestForOverflow()
return;
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2())
@ -1361,9 +1349,7 @@ void CheckCondition::checkPointerAdditionResultNotNull()
return;
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2())