Refactoring: Use range for loops in CheckBool

This commit is contained in:
Daniel Marjamäki 2018-04-23 07:46:37 +02:00
parent b6e89f85d0
commit c6d834ae17
1 changed files with 8 additions and 24 deletions

View File

@ -58,9 +58,7 @@ void CheckBool::checkIncrementBoolean()
return;
const SymbolDatabase *symbolDatabase = _tokenizer->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->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "%var% ++")) {
const Variable *var = tok->variable();
@ -98,9 +96,7 @@ void CheckBool::checkBitwiseOnBoolean()
return;
const SymbolDatabase *symbolDatabase = _tokenizer->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->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "(|.|return|&&|%oror%|throw|, %var% [&|]")) {
const Variable *var = tok->next()->variable();
@ -137,9 +133,7 @@ void CheckBool::checkComparisonOfBoolWithInt()
return;
const SymbolDatabase* const symbolDatabase = _tokenizer->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->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
const Token* const left = tok->astOperand1();
const Token* const right = tok->astOperand2();
@ -192,9 +186,7 @@ void CheckBool::checkComparisonOfFuncReturningBool()
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functionsCount = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functionsCount; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
continue;
@ -256,9 +248,7 @@ void CheckBool::checkComparisonOfBoolWithBool()
const SymbolDatabase* const symbolDatabase = _tokenizer->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->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
continue;
@ -300,9 +290,7 @@ void CheckBool::comparisonOfBoolWithBoolError(const Token *tok, const std::strin
void CheckBool::checkAssignBoolToPointer()
{
const SymbolDatabase *symbolDatabase = _tokenizer->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->classStart; tok != scope->classEnd; tok = tok->next()) {
if (tok->str() == "=" && astIsBool(tok->astOperand2())) {
const Token *lhs = tok->astOperand1();
@ -332,9 +320,7 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
const SymbolDatabase* symbolDatabase = _tokenizer->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->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (!tok->isComparisonOp())
continue;
@ -448,9 +434,7 @@ void CheckBool::checkAssignBoolToFloat()
if (!_settings->isEnabled(Settings::STYLE))
return;
const SymbolDatabase *symbolDatabase = _tokenizer->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->classStart; tok != scope->classEnd; tok = tok->next()) {
if (tok->str() == "=" && astIsBool(tok->astOperand2())) {
const Token *lhs = tok->astOperand1();