Refactoring; Use range for loops

This commit is contained in:
Daniel Marjamäki 2018-12-25 11:47:45 +01:00
parent 486697fc7d
commit c7993df4ff
2 changed files with 16 additions and 17 deletions

View File

@ -1378,18 +1378,17 @@ Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer *tokenizer, const S
Check::FileInfo *CheckUninitVar::getFileInfo() const Check::FileInfo *CheckUninitVar::getFileInfo() const
{ {
const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
std::list<Scope>::const_iterator scope;
MyFileInfo *fileInfo = new MyFileInfo; MyFileInfo *fileInfo = new MyFileInfo;
// Parse all functions in TU // Parse all functions in TU
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { for (const Scope &scope : symbolDatabase->scopeList) {
if (!scope->isExecutable() || scope->type != Scope::eFunction || !scope->function) if (!scope.isExecutable() || scope.type != Scope::eFunction || !scope.function)
continue; continue;
const Function *const function = scope->function; const Function *const function = scope.function;
// function calls where uninitialized data is passed by address // function calls where uninitialized data is passed by address
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { for (const Token *tok = scope.bodyStart; tok != scope.bodyEnd; tok = tok->next()) {
if (tok->str() != "(" || !tok->astOperand1() || !tok->astOperand2()) if (tok->str() != "(" || !tok->astOperand1() || !tok->astOperand2())
continue; continue;
if (!tok->astOperand1()->function()) if (!tok->astOperand1()->function())
@ -1424,18 +1423,18 @@ Check::FileInfo *CheckUninitVar::getFileInfo() const
CheckNullPointer checkNullPointer(mTokenizer, mSettings, mErrorLogger); CheckNullPointer checkNullPointer(mTokenizer, mSettings, mErrorLogger);
for (int argnr = 0; argnr < function->argCount(); ++argnr) { for (int argnr = 0; argnr < function->argCount(); ++argnr) {
const Token *tok; const Token *tok;
if (isUnsafeFunction(&*scope, argnr, &tok)) if (isUnsafeFunction(&scope, argnr, &tok))
fileInfo->readData.push_back(MyFileInfo::FunctionArg(mTokenizer, &*scope, argnr+1, tok)); fileInfo->readData.push_back(MyFileInfo::FunctionArg(mTokenizer, &scope, argnr+1, tok));
if (checkNullPointer.isUnsafeFunction(&*scope, argnr, &tok)) if (checkNullPointer.isUnsafeFunction(&scope, argnr, &tok))
fileInfo->dereferenced.push_back(MyFileInfo::FunctionArg(mTokenizer, &*scope, argnr+1, tok)); fileInfo->dereferenced.push_back(MyFileInfo::FunctionArg(mTokenizer, &scope, argnr+1, tok));
} }
// Nested function calls // Nested function calls
for (int argnr = 0; argnr < function->argCount(); ++argnr) { for (int argnr = 0; argnr < function->argCount(); ++argnr) {
const Token *tok; const Token *tok;
int argnr2 = isCallFunction(&*scope, argnr, &tok); int argnr2 = isCallFunction(&scope, argnr, &tok);
if (argnr2 > 0) { if (argnr2 > 0) {
MyFileInfo::FunctionArg fa(mTokenizer, &*scope, argnr+1, tok); MyFileInfo::FunctionArg fa(mTokenizer, &scope, argnr+1, tok);
fa.id = FUNCTION_ID(function); fa.id = FUNCTION_ID(function);
fa.id2 = FUNCTION_ID(tok->function()); fa.id2 = FUNCTION_ID(tok->function());
fa.argnr2 = argnr2; fa.argnr2 = argnr2;

View File

@ -553,23 +553,23 @@ void CppCheck::checkRawTokens(const Tokenizer &tokenizer)
void CppCheck::checkNormalTokens(const Tokenizer &tokenizer) void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
{ {
// call all "runChecks" in all registered Check classes // call all "runChecks" in all registered Check classes
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { for (Check *check : Check::instances()) {
if (mSettings.terminated()) if (mSettings.terminated())
return; return;
if (tokenizer.isMaxTime()) if (tokenizer.isMaxTime())
return; return;
Timer timerRunChecks((*it)->name() + "::runChecks", mSettings.showtime, &S_timerResults); Timer timerRunChecks(check->name() + "::runChecks", mSettings.showtime, &S_timerResults);
(*it)->runChecks(&tokenizer, &mSettings, this); check->runChecks(&tokenizer, &mSettings, this);
} }
// Analyse the tokens.. // Analyse the tokens..
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { for (const Check *check : Check::instances()) {
Check::FileInfo *fi = (*it)->getFileInfo(&tokenizer, &mSettings); Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings);
if (fi != nullptr) { if (fi != nullptr) {
mFileInfo.push_back(fi); mFileInfo.push_back(fi);
mAnalyzerInformation.setFileInfo((*it)->name(), fi->toString()); mAnalyzerInformation.setFileInfo(check->name(), fi->toString());
} }
} }