Refactoring; Use range for loops

This commit is contained in:
Daniel Marjamäki 2018-07-14 09:49:03 +02:00
parent c60763bc14
commit bb36adb432
1 changed files with 31 additions and 39 deletions

View File

@ -44,11 +44,10 @@ void CheckExceptionSafety::destructors()
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
// Perform check.. // Perform check..
const std::size_t functions = symbolDatabase->functionScopes.size(); for (const Scope * scope : symbolDatabase->functionScopes) {
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
const Function * function = scope->function; const Function * function = scope->function;
if (function) { if (!function)
continue;
// only looking for destructors // only looking for destructors
if (function->type == Function::eDestructor) { if (function->type == Function::eDestructor) {
// Inspect this destructor. // Inspect this destructor.
@ -72,7 +71,6 @@ void CheckExceptionSafety::destructors()
} }
} }
} }
}
} }
@ -88,9 +86,7 @@ void CheckExceptionSafety::deallocThrow()
// Deallocate a global/member pointer and then throw exception // Deallocate a global/member pointer and then throw exception
// the pointer will be a dead pointer // the pointer will be a dead pointer
const std::size_t functions = symbolDatabase->functionScopes.size(); for (const Scope * scope : symbolDatabase->functionScopes) {
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
// only looking for delete now // only looking for delete now
if (tok->str() != "delete") if (tok->str() != "delete")
@ -154,13 +150,13 @@ void CheckExceptionSafety::checkRethrowCopy()
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) { for (const Scope &scope : symbolDatabase->scopeList) {
if (i->type != Scope::eCatch) if (scope.type != Scope::eCatch)
continue; continue;
const unsigned int varid = i->bodyStart->tokAt(-2)->varId(); const unsigned int varid = scope.bodyStart->tokAt(-2)->varId();
if (varid) { if (varid) {
for (const Token* tok = i->bodyStart->next(); tok && tok != i->bodyEnd; tok = tok->next()) { for (const Token* tok = scope.bodyStart->next(); tok && tok != scope.bodyEnd; tok = tok->next()) {
if (Token::simpleMatch(tok, "catch (") && tok->next()->link() && tok->next()->link()->next()) { // Don't check inner catch - it is handled in another iteration of outer loop. if (Token::simpleMatch(tok, "catch (") && tok->next()->link() && tok->next()->link()->next()) { // Don't check inner catch - it is handled in another iteration of outer loop.
tok = tok->next()->link()->next()->link(); tok = tok->next()->link()->next()->link();
if (!tok) if (!tok)
@ -182,15 +178,15 @@ void CheckExceptionSafety::checkCatchExceptionByValue()
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) { for (const Scope &scope : symbolDatabase->scopeList) {
if (i->type != Scope::eCatch) if (scope.type != Scope::eCatch)
continue; continue;
// Find a pass-by-value declaration in the catch(), excluding basic types // Find a pass-by-value declaration in the catch(), excluding basic types
// e.g. catch (std::exception err) // e.g. catch (std::exception err)
const Variable *var = i->bodyStart->tokAt(-2)->variable(); const Variable *var = scope.bodyStart->tokAt(-2)->variable();
if (var && var->isClass() && !var->isPointer() && !var->isReference()) if (var && var->isClass() && !var->isPointer() && !var->isReference())
catchExceptionByValueError(i->classDef); catchExceptionByValueError(scope.classDef);
} }
} }
@ -245,9 +241,7 @@ void CheckExceptionSafety::nothrowThrows()
{ {
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size(); for (const Scope * scope : symbolDatabase->functionScopes) {
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
const Function* function = scope->function; const Function* function = scope->function;
if (!function) if (!function)
continue; continue;
@ -286,9 +280,7 @@ void CheckExceptionSafety::unhandledExceptionSpecification()
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size(); for (const Scope * scope : symbolDatabase->functionScopes) {
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
// only check functions without exception epecification // only check functions without exception epecification
if (scope->function && !scope->function->isThrow() && if (scope->function && !scope->function->isThrow() &&
scope->className != "main" && scope->className != "wmain" && scope->className != "main" && scope->className != "wmain" &&