Refactoring; Use range for loops

This commit is contained in:
Daniel Marjamäki 2018-07-13 23:51:22 +02:00
parent 594e07acaa
commit d759015d99
1 changed files with 11 additions and 12 deletions

View File

@ -1875,12 +1875,12 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
} }
} while (again); } while (again);
for (std::list<Variable>::const_iterator var = scope->varlist.begin(); var != scope->varlist.end(); ++var) { for (const Variable &var : scope->varlist) {
if (var->name() == tok->str()) { if (var.name() == tok->str()) {
if (tok->varId() == 0) if (tok->varId() == 0)
mSymbolDatabase->debugMessage(tok, "CheckClass::isMemberVar found used member variable \'" + tok->str() + "\' with varid 0"); mSymbolDatabase->debugMessage(tok, "CheckClass::isMemberVar found used member variable \'" + tok->str() + "\' with varid 0");
return !var->isStatic(); return !var.isStatic();
} }
} }
@ -1905,8 +1905,8 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const
{ {
if (!tok->function()) { if (!tok->function()) {
for (std::list<Function>::const_iterator i = scope->functionList.cbegin(); i != scope->functionList.cend(); ++i) { for (const Function &func : scope->functionList) {
if (i->name() == tok->str()) { if (func.name() == tok->str()) {
const Token* tok2 = tok->tokAt(2); const Token* tok2 = tok->tokAt(2);
size_t argsPassed = tok2->str() == ")" ? 0 : 1; size_t argsPassed = tok2->str() == ")" ? 0 : 1;
for (;;) { for (;;) {
@ -1916,7 +1916,7 @@ bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const
else else
break; break;
} }
if (argsPassed == i->argCount() || (argsPassed < i->argCount() && argsPassed >= i->minArgCount())) if (argsPassed == func.argCount() || (argsPassed < func.argCount() && argsPassed >= func.minArgCount()))
return true; return true;
} }
} }
@ -2260,8 +2260,7 @@ void CheckClass::checkVirtualFunctionCallInConstructor()
continue; continue;
const std::list<const Token *> & virtualFunctionCalls = getVirtualFunctionCalls(*scope->function, virtualFunctionCallsMap); const std::list<const Token *> & virtualFunctionCalls = getVirtualFunctionCalls(*scope->function, virtualFunctionCallsMap);
for (std::list<const Token *>::const_iterator it = virtualFunctionCalls.begin(); it != virtualFunctionCalls.end(); ++it) { for (const Token *callToken : virtualFunctionCalls) {
const Token * callToken = *it;
std::list<const Token *> callstack(1, callToken); std::list<const Token *> callstack(1, callToken);
getFirstVirtualFunctionCallStack(virtualFunctionCallsMap, callToken, callstack); getFirstVirtualFunctionCallStack(virtualFunctionCallsMap, callToken, callstack);
if (callstack.empty()) if (callstack.empty())
@ -2360,8 +2359,8 @@ void CheckClass::virtualFunctionCallInConstructorError(
ErrorPath errorPath; ErrorPath errorPath;
int lineNumber = 1; int lineNumber = 1;
for (std::list<const Token *>::const_iterator it = tokStack.begin(); it != tokStack.end(); ++it) for (const Token *tok : tokStack)
errorPath.emplace_back(*it, "Calling " + (*it)->str()); errorPath.emplace_back(tok, "Calling " + tok->str());
if (!errorPath.empty()) { if (!errorPath.empty()) {
lineNumber = errorPath.front().first->linenr(); lineNumber = errorPath.front().first->linenr();
errorPath.back().second = funcname + " is a virtual method"; errorPath.back().second = funcname + " is a virtual method";
@ -2394,8 +2393,8 @@ void CheckClass::pureVirtualFunctionCallInConstructorError(
const char * scopeFunctionTypeName = scopeFunction ? getFunctionTypeName(scopeFunction->type) : "constructor"; const char * scopeFunctionTypeName = scopeFunction ? getFunctionTypeName(scopeFunction->type) : "constructor";
ErrorPath errorPath; ErrorPath errorPath;
for (std::list<const Token *>::const_iterator it = tokStack.begin(); it != tokStack.end(); ++it) for (const Token *tok : tokStack)
errorPath.emplace_back(*it, "Calling " + (*it)->str()); errorPath.emplace_back(tok, "Calling " + tok->str());
if (!errorPath.empty()) if (!errorPath.empty())
errorPath.back().second = purefuncname + " is a pure virtual method without body"; errorPath.back().second = purefuncname + " is a pure virtual method without body";